Worked examples — Vanishing gradients in RNNs
This page is the "no scenario left behind" companion to Vanishing gradients in RNNs. Before we compute anything, let us agree on what all the symbols mean, because every example below reuses them.
The next figure plots exactly this: the gradient factor against the gap for the three defining bases , , . Follow the blue curve diving toward zero (Example 1), the flat green line at (Example 3), and the orange curve rocketing up (Example 2) — the three examples share one picture.

The scenario matrix
Every question this topic can throw at you is one cell of this table. The examples that follow are each tagged with the cell they cover, so by the end no cell is left unworked.
| # | Case class | Concrete trigger | Expected behaviour |
|---|---|---|---|
| A | Shrinking weight, no activation | , linear | Exponential vanish |
| B | Growing weight | Exponential explode | |
| C | Boundary / degenerate | exactly | Neither — gradient preserved |
| D | Negative / sign-flip factor | eigenvalue | Vanishing magnitude + oscillating sign |
| E | Saturated / degenerate step | on one step | Near-zero factor that step |
| F | Saturation stacked on weight | every step | Even faster vanish |
| G | Limiting behaviour | Factor or | |
| H | Real-world word problem | subject–verb agreement across a clause | Can it learn the link? |
| I | Exam twist: LSTM gate | forget gate near | Vanish defeated |
| J | Exam twist: mixed rates | per-step varies with | One learning rate can't fix |
Example 1 — Cell A: shrinking weight, pure linear
Forecast: guess before reading — will the influence be closer to , to , or to ?
- Write the per-step derivative. From , differentiate w.r.t. : . Why this step? does not depend on , so it drops; the coefficient is the whole local derivative.
- Chain across the gap. . Why this step? Each step multiplies the same factor, so a gap of steps means the factor to the th power (note-passing line of people).
- Evaluate. . Why this step? This is the actual size of the "note" that survives across the gap .
- Turn into a parameter update. update . Why this step? A gradient this small produces a change too tiny to move the weights — the dependency is effectively unlearnable.
Verify: : take logs, , and . ✓ Consistent with step 3.
Example 2 — Cell B: growing weight (the opposite failure)
Forecast: vanish or blow up?
- Write the per-step derivative . Why this step? Exactly as in Example 1, step 1: differentiating w.r.t. drops the input term and leaves the coefficient as the local derivative.
- Chain: . Why this step? Reuse of the same factor across the gap again.
- Evaluate: . Why this step? Now each pass brightens the note, so it grows without bound — this is the Exploding Gradients regime, cured by Gradient Clipping.
Verify: , . ✓ Opposite sign of exponent-effect from Example 1 — confirming vanish and explode are two ends of one dial (the blue vs orange curves in the figure above).
Example 3 — Cell C: the exact boundary
Forecast: what does raised to the th power do?
- Per-step factor .
- Chain: exactly. Why this step? Multiplying by changes nothing, no matter how large the gap .
- Interpret: this is the ideal — an uninterrupted "gradient highway" (the flat green line in the opening figure). It is exactly what the LSTM forget gate and Residual Connections deliberately engineer by keeping the effective factor near .
Verify: . ✓ The boundary is neither vanish nor explode — this is why (orthogonal initialization) is the target for plain RNNs.
Example 4 — Cell D: negative factor (sign-flipping oscillation)
Forecast: does the magnitude vanish like Example 1, and what does the sign do?
- Per-step derivative . Why this step? Same differentiation as before; the coefficient is simply negative now. A norm can never be negative, so this sign lives in the eigenvalue (spectral radius with sign), not the spectral norm — a real matrix can have negative eigenvalues, and a scalar factor can be .
- Chain across the gap: . Why this step? A negative base raised to a power keeps flipping sign: odd gives a negative factor, even gives positive.
- Split magnitude and sign. ; but . Why this step? The magnitude still vanishes exactly like Example 1 — sign flipping does not rescue it. The oscillating sign just means the gradient's direction alternates every step, which can slow or destabilise learning even before it vanishes.
Verify: (positive); (negative). ✓ Magnitude identical to Example 1, sign alternates with parity of .
Example 5 — Cell E: a single saturated / degenerate step
Forecast: does the big weight rescue the flat tanh, or does the flat tanh win?
- Local derivative (the standard BPTT form). Why this step? Both factors are present: the tanh slope and the weight both multiply. The weight magnitude does not disappear.
- Evaluate the slope: , so . Why this step? Deep in saturation the tanh curve is flat, so its slope is nearly — see the Activation Functions shape in the next figure.
- Multiply in the weight: factor . Why this step? The weight does affect the answer — it doubles the small factor. But because the tanh slope is so tiny, even a large weight leaves the factor near zero: the saturated step dominates, though it does not literally cancel .
Verify: ; times . ✓ Notice the weight visibly scales the result — it is not irrelevant, just outmatched.

The figure above shows tanh (blue) flattening out and its slope (red) collapsing to zero as grows. The red dot marks where the slope has already nearly vanished — at it is off the bottom of the plot.
Example 6 — Cell F: saturation stacked on a shrinking weight
Forecast: guess the order of magnitude — ? ? ?
- Combine per-step factors: effective multiplier . Why this step? The tanh slope and the weight norm are separate factors that multiply — the parent note stresses not to conflate them.
- Chain steps: .
- Evaluate: . Why this step? This is below float32's smallest normal number () — the gradient is numerically zero, not just small.
Verify: , so . ✓ Two separate factors ( and ) confirmed multiplying.
Example 7 — Cell G: limiting behaviour as the gap grows
Forecast: roughly steps, steps, or steps?
- Set up the inequality: we want . Why this step? We are asking "how long a note-passing line before the note is <1% bright?"
- Take logs: (inequality flips because ). Why this step? Logs turn the exponent into a solvable linear inequality; dividing by a negative flips the sign.
- Evaluate: , so . Why this step? Even a gentle still kills long-range signal — just at a longer horizon. As , always.
Verify: while , so the first integer crossing is . ✓
Example 8 — Cell H: the real-world word problem
Forecast: more than half, or almost nothing?
- Count the gap: tokens between "cat" and "was".
- Compute survival: . Why this step? Each intervening word re-multiplies the carried memory by ; the "cat" signal must survive such multiplications on its way forward, and the correcting gradient must survive the same on the way back.
- Evaluate: , i.e. about . Why this step? Under of the original "cat" memory component (and equally of the returning gradient) still reaches across the clause — separately, the parameter update is this gradient times the learning rate, but the point here is that the raw signal itself is already down to . This is exactly the case Attention Mechanisms and LSTMs were built to rescue.
Verify: . ✓ (.)
Example 9 — Cell I: the LSTM forget-gate escape (exam twist)
Forecast: will behave like the vanished , or survive?
- Chain the gate: . Why this step? The additive cell update makes the local derivative just — no weight matrix, no tanh slope stacked on top.
- Evaluate: . Why this step? Over of the gradient survives steps — versus for the plain RNN. A gate near builds the highway.
- Contrast: plain RNN vs LSTM — a factor of more signal. Why this step? Same gap, same "exponential" form, but a base close to delays vanishing enormously. GRUs achieve the same with a single update gate.
Verify: : , . Ratio . ✓
The figure below overlays both survival curves against the gap : the red plain-RNN curve crashes to by while the green LSTM curve holds at — the highway made visible.

Example 10 — Cell J: mixed / varying per-step rates (exam twist)
Forecast: can a single learning rate be "just right" for both the near and far parameters?
- Product with varying factors. When changes per step the chain is a product of different numbers: , not a single base to a power. Why this step? Example 1 assumed every equal; in reality each step's slope and weight differ, so we must multiply the actual sequence of factors. This is the honest general form behind all earlier examples.
- Recent gradient (gap ): the last two factors are each, so -product . Why this step? A recent parameter only has to survive mild multiplications, so its gradient is near — perfectly healthy.
- Early gradient (gap ): the full product is . Why this step? The first parameter's signal must run the whole gauntlet: the mild steps and the shrinking steps stack up.
- Evaluate the early product: . Why this step? The term dominates — the early gradient has still essentially vanished despite the friendly recent steps.
- Pick lr to boost the early step to update : . Why this step? To move the far-away parameters at all, we need a huge learning rate.
- Apply that lr to the recent step: update . Why this step? The recent parameters get slammed with an update of size — wildly unstable. One learning rate cannot serve a gap- gradient of and a gap- gradient of at once. This is the parent note's "Mistake 2"; the cure is adaptive optimizers (Adam, RMSprop) that keep per-parameter rates, plus gated architecture.
Verify: ; ; . ✓ Recent gradient vs early — a spread that no single lr can bridge.
Recall Self-test — reveal after guessing
Per-step factor , gap , gradient factor? ::: Per-step factor , gap ? ::: (explodes) Per-step factor exactly , any gap ? ::: — preserved, the ideal highway Per-step eigenvalue , gap ? ::: : same tiny magnitude as , but negative (odd gap) A single step with and weight ? ::: — near-zero, weight only scales it LSTM forget gate over gap ? ::: , over survives Varying factors ? ::: — the shrinking steps still dominate