Last chapter's network failed because it summed its tokens into one vector before doing anything else — by the time a weight ever touched the data, the order was already gone. The fix isn't a bigger network. It's a different shape: process one token at a time, and carry something forward.
A recurrent network keeps a single running number, the hidden state, starting at . At every step it folds in the next token and its own previous state: depends on token 1, depends on token 2 and on — which already encoded token 1. Nothing is ever summed away. Slide and watch how much the earlier token's fingerprint survives into .
- — the hidden state at timestep : the running summary the network carries forward.
- — the input token at timestep .
- — the weight matrix applied to the current input token.
- — the weight matrix applied to the previous hidden state (the recurrent weight).
- — the hidden state carried over from the previous timestep.
- — the bias term.
- — the squashing activation that keeps the hidden state bounded between and .
- Weights shared across time
The same weights , , are reused at every timestep — exactly the "share one small set of weights across many positions" idea from convolution, just applied across time instead of space.
- Recurrence carries the whole history
The recurrence is what makes depend on the entire sequence seen so far, not just the token that just arrived.
These are the exact two sequences from Chapter 5 — "X then Y" and "Y then X" — the ones a sum-pooled network could never tell apart, because they pooled to the identical vector no matter the order. Watch here: it's already different for the two sequences, before the second token even arrives, simply because the RNN saw a different first token. Sum-pooling could never do that.
With , , :
- "X then Y"
, then .
- "Y then X"
, then .
- Compare
Same weights, same two tokens — but processed in the opposite order, the final hidden states land on opposite signs. That sign is something a simple readout layer can actually use.
Adjust the recurrent weight until the two sequences’ final hidden states differ by more than 1.9.
Carrying a hidden state forward, instead of pooling everything at once, is what let this network do something Chapter 5's architecture couldn't do at any weight setting. But notice how far you had to push to get a confident separation — and recall there was one particular weight where the two sequences collapsed back to the same state. Pushing a recurrent weight that hard, repeated over a long sequence, is exactly what causes the next chapter's problem: vanishing gradients.