Chapter 6 ended with a warning: pushing a recurrent weight hard enough to get a confident answer, repeated over many timesteps, is exactly the vanishing-gradient problem from Part III — just running through time instead of through layers.
An RNN (Recurrent Neural Network) unrolled over timesteps is a -layer chain with the same weight reused at every layer — Part III's vanishing-gradient math, applied to time. Slide the timestep count and watch the plain RNN's gradient (dim line) collapse by roughly an order of magnitude every step, while an LSTM (Long Short-Term Memory)'s cell-state gradient (bold line) barely bends.
A plain RNN's gradient reaching timestep 1 from timestep is a product of factors, each one a squashing derivative times the recurrent weight:
- — the gradient of the last hidden state with respect to the first: how much a change at step 1 still affects step .
- — the derivative of the tanh activation at timestep 's pre-activation, a value always less than that shrinks the gradient at every step.
- — the recurrent weight reused at every timestep.
- — the total number of timesteps, and the index running from up to .
An LSTM keeps a separate cell state , and its backward path through the cell state is just:
- — the gradient of the final cell state with respect to the first cell state.
- — the LSTM's cell state at timestep : a separate running memory, distinct from the hidden state.
- — the forget gate at timestep : how much of the previous cell state to keep, between and .
- No squashing-derivative factor
Unlike the plain RNN's gradient, there's no factor in this product — nothing here is forced below by a squashing derivative at every step.
- A forget gate near 1 preserves the gradient
If the forget gate stays close to , this product barely shrinks at all — the "constant error carousel" that gives LSTMs their long memory.
Both curves use the exact same weight value — this isn't about the LSTM having bigger numbers to work with. The plain RNN multiplies by a squashing derivative and the weight at every step; the LSTM's cell-state path multiplies by only the forget gate. Removing one shrinking factor per timestep is the entire difference, and over enough timesteps it compounds into an astronomical gap.
At weight (or forget gate) and timesteps:
- Plain RNN gradient
Each timestep multiplies by that step's own . The recurrence's input is constant every step, so converges fast toward a fixed point (), where — a steady-state per-step factor of . Multiplying nine such factors together (nine transitions across ten timesteps): — the same order of magnitude as the actual , the small difference coming from the first couple of steps, before has fully settled, contributing slightly larger factors. Nine orders of magnitude gone either way.
- LSTM cell-state gradient
— still very much alive.
- Compare
The ratio between them is over a billion, using the same on both sides.
Slide the number of timesteps until the LSTM’s cell-state gradient is more than 1e+6 times larger than the plain RNN’s.
Gating doesn't eliminate the product-of-many-factors structure that causes vanishing gradients — it just removes the squashing derivative from one of the paths, so that path can carry a signal across far more timesteps before it's gone. Everything built so far — convolution, pooling, recurrence, gating — has operated on numeric vectors. The next few chapters turn to how text becomes those vectors in the first place.