Worked examples — Recurrent neural networks — hidden state, BPTT
The scenario matrix
Every BPTT calculation is built from the same three moving parts:
- the hidden state value (near ? near ? exactly ?),
- the recurrent weight (magnitude , , , or negative?),
- the loss (one output at the end, or an output at every step?).
The table below lists every combination that behaves differently. The last column names the example that covers it.
| Cell | Scenario | What's special | Example |
|---|---|---|---|
| A | Small , unsaturated | The "healthy" baseline | Ex 1 |
| B | start | Degenerate initial state → a term vanishes | Ex 1, Ex 2 |
| C | Negative gradient sign | Blame signal is negative | Ex 1 |
| D | Positive gradient sign | Blame signal is positive | Ex 2 |
| E | Saturated () | → vanishing | Ex 3 |
| F | over many steps | Gradient explodes | Ex 4 |
| G | Loss at every step (multi-output) | has a direct term every step | Ex 5 |
| H | Long chain, product of Jacobians | Watch decay in numbers | Ex 6 |
| I | Real-world flight word problem | Turn units + physics into the update | Ex 7 |
| J | Exam twist: linear ( removed) | Collapses to pure | Ex 8 |
| K | Borderline | : neither blows up nor dies | Ex 9 |
| L | Negative | Blame alternates sign each hop | Ex 10 |
We keep everything scalar (one number, not vectors) so you can check every digit by hand. For scalars the fearsome matrix transpose is just the number , and is ordinary multiplication.
The picture below plots (blue) against its backward multiplier (yellow) — read the legend inside the figure for which colour is which, and the labelled axes for the scale. Read it as your master key for every example: wherever blue is flat (saturated), yellow is near → blame dies; wherever blue is steep (near the origin), yellow is near → blame passes freely. We will point back to this shape in Ex 3.

Example 1 — Cell A, B, C: the healthy baseline
Forecast: Guess the sign first. is below the target , so the loss wants bigger. Since , the step-1 contribution is dead. Do you expect the final gradient positive or negative?
- Forward, step 1. , so . Why this step? The recipe's forward line — we cannot blame anything until we know the actual states.
- Forward, step 2. , so . Why? Same rule, now the previous state feeds in through — this is the memory in action.
- Output blame. . Why negative? means we undershot; the derivative of is , which is negative here. This is Cell C — a negative blame signal.
- Set . Since the only loss is at step 2, . Why no future term? There is no step 3, so nothing flows back from the future.
- Carry blame to step 1. . Compute , so . Why? Backward blame line: step 1's state only matters through the future, filtered by Tanh's twin.
- Sum the weight gradient over both steps. Term 1 — killed by (Cell B). Term 2 . Why two terms? "Same weight, sum the blame" — did a job at step 1 (times ) and step 2 (times ).
Answer: .
Recall Verify
Sign check: gradient is negative, so gradient descent () increases . A bigger makes bigger makes closer to . Consistent with "we undershot the target." ✅ The zero first term confirms Cell B: a zero start erases step-1's contribution.
Example 2 — Cell B, D: same net, target below → positive gradient
Forecast: is now above target . We want it smaller. Sign of the gradient?
- Forward is unchanged. . Why? The forward pass does not depend on the target.
- Output blame flips sign. . Cell D — positive blame. Why? Derivative of is , which is positive.
- , only-end loss.
- Weight gradient, second term only (first dies on ):
Answer: .
Recall Verify
Positive gradient ⇒ descent decreases ⇒ smaller ⇒ smaller ⇒ closer to target . ✅ Note it is larger in magnitude than Ex 1 because the error is much bigger than .
Example 3 — Cell E: saturated , gradient vanishes
Forecast: Both values are large, so . What happens to Tanh's twin ?
-
Forward. , . , . Why? Straight recipe — but notice how close to we already are. This is the flat-top region of the master-key figure (s01).
-
Tanh's twin is tiny. . That's the geometric flatness of the figure below. Why does this matter? Every backward step multiplies by this factor. Cell E starts here.
-
Output blame. . Why so small? We are already almost exactly at target .
-
Carry to step 1. . Why so tiny? Both the small error and the tiny Tanh's twin multiply together — the gradient has vanished before reaching step 1.
Answer: — effectively zero.
Recall Verify
: the blame shrank by crossing one step. Over 10 saturated steps it would shrink by . That is exactly the vanishing gradient the parent warned about. ✅
Example 4 — Cell F: , gradient explodes
Forecast: Each backward hop multiplies by . Travelling from step 5 to step 1 is 4 hops (5→4→3→2→1). Over those 4 hops?
- Count the hops first. Going from state 5 to state 1 you cross the arrows , , , — that is backward hops. Why care? The number of hops is the exponent below; "5 states" but "4 hops between the ends."
- Per-step multiplier. . Why ? With , Tanh's twin — no shrinkage from the nonlinearity here.
- Chain the 4 hops (step 5 → step 1). . Why a product, and why does it become a power? The chain rule says a two-hop derivative is the product of one-hop derivatives: . When every hop equals the same number , multiplying copies of is by definition of a power. That is the whole reason powers appear.
- General law. with ; here . Cell F — explosion because .
Answer: the blame is amplified over 4 hops; over 20 hops it would be .
Recall Verify
. A gradient a million times too big overflows the optimizer — this is why we use gradient clipping. Compare to Ex 3 where gave vanishing. The switch happens exactly at . ✅
Example 5 — Cell G: a loss at every step (multi-output)
Forecast: Now has a direct term (its own loss ) plus the future term. Bigger or smaller than Ex 1?
- Forward unchanged. .
- . Only touches : . Why? has no future.
- now has TWO parts. Direct part . Future part . So . Cell G — the direct term at every step. Why add? Multivariate chain rule: influences the loss through both directly and via . Sum the paths.
- Weight gradient, both steps: First term (still ). Second .
Answer: (same value as Ex 1, because still kills the term that lives in).
Recall Verify
Even though ballooned to , it multiplies , so the weight gradient is unchanged. But if we also asked for , the step-1 term is — now the extra loss does show up. ✅
Example 6 — Cell H: a 4-step chain, watch numerically
Forecast: Per-step multiplier is . So the blame should shrink geometrically.
- Where does come from? The final blame is . We deliberately picked the target so this equals exactly — a clean round number to watch decay. Why allowed? The target is just a number we compare against; choosing it fixes the size of the starting blame.
- Per-step factor. . Why one number? All states equal, so every hop multiplies by the same .
- .
- .
- . Why the pattern? — the promised decay, made of real digits.
Answer: .
Recall Verify
matches exactly. The blame from step 4 reaching step 1 kept only of its strength — a mild version of vanishing. With and 30 steps you'd keep : unlearnable. This is why gated cells exist. ✅
Example 7 — Cell I: real flight-data word problem (full backward pass)
Forecast: Steady positive inputs + memory retention → the state should ramp up toward . Does it get there in 3 seconds?
- Second 1. , . Why? Turn the physics into the recipe — is the fresh evidence, is "no history yet."
- Second 2. , . Why ? The net remembers of last second's belief and adds new evidence.
- Second 3. , . Reads: memory has ramped — climbing but not yet at .
- Output blame at the final step. . Why ? The loss is ; by the power-and-chain rule . Negative because we undershot the target .
- Carry blame to step 2. No output loss at step 2, so the direct term is : Why? Step 2's memory only reaches the loss through step 3, filtered by Tanh's twin .
- Carry blame to step 1. Again no output loss at step 1: Why? Same backward hop, one step earlier — the blame is shrinking as it travels back (each hop's factor here).
- Sum the weight gradient over all three steps (weight was used at each step, multiplying the previous state):
- Term 1 — killed by the zero start.
- Term 2 .
- Term 3 .
- Sum . Why sum three terms? "Same weight, sum the blame" — one parameter, one job per step, gradients add.
Answer: ; .
Recall Verify
Units: everything is normalized/dimensionless, so the gradient is a pure number — good. Sign: negative gradient ⇒ descent raises ⇒ the net remembers more of its rising history ⇒ climbs toward the "steady-climb = 1" target. Physically sensible. This is the kind of update used in time-series forecasting on flight data. ✅
Example 8 — Cell J: exam twist, remove (linear RNN)
Forecast: No squashing means the state can grow without a ceiling and Tanh's twin becomes... what?
- Tanh's twin dies. With , the derivative — no factor at all. Why? , so the nonlinearity's damping is gone. This is Cell J.
- Forward (pure linear recurrence). . . . Why no ceiling? Nothing squashes it; the state just accumulates.
- Jacobian over 2 hops. . Why exactly ? With gone the whole network is a single linear map, and its Jacobian is pure — vanishing if , exploding if , with no way to gate in between.
Answer: , . What breaks: the net collapses to one linear map (stacking layers buys nothing) and its gradients are locked into pure behaviour — exactly the backprop pathology the parent's mistake box warns about.
Recall Verify
Stack the two linear steps: . Differentiate w.r.t. : . And ✅ — both match.
Example 9 — Cell K: the borderline
Forecast: The naive fear is " means , so blame is preserved." But Tanh's twin is still . Does the blame stay put, or slowly fade?
- Per-hop factor. . Why not exactly 1? Even with , the nonlinearity contributes its twin . So , just under the knife-edge.
- March back 4 hops (step 5 → step 1).
- Why powers again? Same-number-per-hop ⇒ (the power rule from Ex 4).
- Interpretation. Blame kept of its strength over 4 steps — neither vanished (Ex 6: ) nor exploded (Ex 4: ). This is the slow, graceful borderline. Only a strictly linear (-free) unit with preserves blame exactly.
Answer: .
Recall Verify
matches . Ranking the three regimes by what fraction survives 4 hops: explode (Ex 4) borderline (here) vanish (Ex 6). The borderline sits sensibly in the middle. ✅ Lesson: with , even still slowly forgets — this is why gated cells build a linear identity path to hit exactly.
Example 10 — Cell L: negative , alternating-sign blame
Forecast: Each hop now multiplies by a negative number . What does multiplying by a negative do to the sign, step after step?
- Per-hop factor. . Why negative? Tanh's twin is always positive, but is negative — the product inherits the sign of . This is Cell L.
- March back.
- Why the flip-flop? Multiplying by a negative number flips the sign every hop, so blame alternates as it travels back in time.
- Magnitude still governed by . , so despite the sign flips the size still shrinks like — it still vanishes, just with oscillating sign.
Answer: (alternating sign, shrinking magnitude).
Recall Verify
; ; . The general term captures both the alternating sign and the shrinking magnitude. Vanish/explode is set by ; the sign of only decides the oscillation. ✅