← Contents Volume III · Lecture 5

Volume III · Remembering — Recurrent Networks

5

A Network That Feeds Itself

Pass a message hand to hand down a long line of people, each one half-remembering what they were told and half-mishearing it before repeating it to the next. By the far end of the line, almost nothing of the original sentence survives. A recurrent network is that line, and its hidden state is the message.

The mental model

A network that reuses its own output as part of its next input can in principle remember anything — in practice, its memory of anything more than a few steps back decays to nothing, or explodes.

One equation, run in a loop

Everything a vanilla recurrent network does is contained in one small recurrence, applied again at every timestep of a sequence. A hidden state is produced by mixing the previous hidden state with the current input, then squashing the result through a nonlinearity:

The vanilla RNN recurrence ht = tanh( Whh ht-1 + Wxh xt )

Notice what is not there: no separate memory, no gate, no mechanism deciding what to keep and what to discard. The hidden state ht is the network's entire account of everything it has seen so far, and it is produced by the same two weight matrices, Whh and Wxh, at every single step. Run the recurrence a thousand times and you have used the same two matrices a thousand times over.

SAME CELL, UNROLLED THREE TIMES ht-2 ht-1 ht Whh, tanh Whh, tanh the identical matrix, every arrow above GRADIENT FLOWS BACK THROUGH EVERY COPY
Figure 5a Three copies of one cell, not three different cells — every arrow above is a multiplication by the same Whh and the same tanh. Backpropagation through time sends the gradient back along the bottom path, through every one of those identical multiplications in turn.

Backpropagation through time

Training a recurrent network means computing how the loss at the final timestep depends on the hidden state many steps earlier — and by the chain rule, that dependency is a product of every intermediate step's local derivative, one factor per timestep between the two. Because every step reuses the same weight matrix and the same activation function, this is not a product of many different terms. It is the same term, multiplied by itself, over and over.

The gradient across T steps, roughly ∂hT / ∂h0 ≈ ( Whh )T × ∏ tanh′( · )

Each tanh′ factor is at most 1, and typically far smaller away from the origin, since tanh saturates almost everywhere except a narrow band near zero. So the product on the right shrinks with every additional step, while the (Whh)T term is repeatedly applying the same matrix — whose effect over T applications is governed entirely by its dominant eigenvalue.

Vanishing, or exploding

Combine the two effects — the repeated matrix and the repeated derivative — and the outcome is decided almost entirely by one number: the dominant eigenvalue of Whh, scaled by the local tanh derivative. If that scaled eigenvalue is less than one, every additional timestep multiplies the gradient by a factor below one, and the gradient shrinks exponentially in T. Push it back twenty or thirty steps and it is indistinguishable from zero — the network receives no signal at all about how an early timestep should have behaved differently.

If the scaled eigenvalue is greater than one instead, the same exponentiation runs the other way: the gradient grows exponentially in T, and training diverges, often visibly, as loss spikes or turns to NaN. Both failure modes come from the identical mechanism — a single quantity raised to a large power — which is why they are always discussed as a pair rather than as two separate bugs.

GRADIENT MAGNITUDE, PROPAGATING BACKWARD t t − 7 DIRECTION OF BACKPROPAGATION
Figure 5b Each bar is the gradient's magnitude one further step back through the unrolled chain. With a scaled eigenvalue below one, the shrinkage compounds — by seven steps back the signal is already too small to move a weight in any useful direction.
Plate 5.1 The one number that decides everything, made draggable. Set λ to 0.9 and drag T past 12 — the boundary this lecture names as roughly what a vanilla RNN can carry — and watch the bar shrink toward nothing well before you get there. Nudge λ just over 1.0 instead and the same chart runs away the other direction. Both failures, the lecture's own point, are one quantity raised to a power.

What a dozen steps buys you

Bengio, Simard and Frasconi made the same point rigorously in 1994: gradient-based learning in a recurrent network becomes exponentially harder as the dependency it must learn spans more timesteps, and this is a property of the architecture, not a symptom of a poorly tuned run. The practical consequence is blunt. A vanilla RNN cannot reliably learn dependencies spanning more than roughly a dozen or so timesteps — a pronoun referring back to a noun ten words earlier is already near the edge of what it can carry.

That limit is the whole reason the next lecture exists. If the problem is that a single pathway is repeatedly multiplied and squashed, the fix is to give the network a second pathway that updates by addition instead — and to let the network itself learn when to add, when to overwrite, and when to forget.

How the recurrence behaves, by regime
RegimeConditionSymptom
Vanishingscaled dominant eigenvalue < 1gradient shrinks exponentially in T; early steps get no update
Explodingscaled dominant eigenvalue > 1gradient grows exponentially in T; loss spikes or diverges
Balancedscaled dominant eigenvalue ≈ 1rare and fragile — a small perturbation flips the regime

Read the primary source