3.5.2 · D3Sequence Models

Worked examples — Backpropagation through time

1,873 words9 min readBack to topic

Before anything else, three symbols you must own (all from the parent — re-anchored here so line one is readable):


The scenario matrix

Every worked example below is tagged with the cell it covers. The columns are the distinct behaviours BPTT can produce.

Cell Scenario What is being stress-tested Example
A Small weight Gradient shrinks backward → foreshadows vanishing Ex 1
B Large weight Gradient grows backward → foreshadows exploding Ex 2
C Negative Sign flips each step; direction of the update Ex 3
D Zero input / degenerate () Time-links cut; only the local term survives Ex 4
E Saturated () kills the gradient Ex 5
F Negative target → negative Loss pushing the state down Ex 6
G Real-world word problem Reading a story into Ex 7
H Exam twist: 3 steps, share the chain Full recursion, no shortcuts Ex 8

The reusable rules (all from the parent, restated so this page stands alone):

Figure — Backpropagation through time

The blueprint above is your map: each example is a walk right-to-left along the bottom arrows, and the figure marks where the gate sits.


Cell A — the gradient that shrinks

  1. Forward. , . Why: apply the forward line twice; each memory feeds the next.
  2. Backward, last step. . Why: the last step has no future, so is purely the local loss slope.
  3. Backward, step 1. . Why: two sources — local loss plus the future loss squeezed by the gate and the weight.
  4. Weight gradient. , . . Why: multiply each pre-activation gradient by the memory that entered that step.

Verify: deletes step 1's contribution, so only step 2 counts. — the wrong (no-) answer would be , exactly double. ✓ (matches parent).


Cell B — the gradient that grows

  1. Forward. . . Why: bigger pushes the pre-activation higher, so is closer to .
  2. . .
  3. . . . Why: even though is starting to saturate (small gate ), the large weight partly compensates.
  4. Weight gradient. . .

Verify: the un-gated future multiplier would explode the chain, but the gate tames it here — this is exactly why LSTMs replace the gate. ✓


Cell C — negative weight flips the sign

  1. Forward. . . Why: the negative recurrent term subtracts the past memory, so lands near zero.
  2. . (negative — the state is below target).
  3. . . . Why: two negatives multiply to a positive, so the future term adds here — sign bookkeeping matters.
  4. Weight gradient. . .

Verify: gradient is negative — gradient descent will increase (make it less negative), pulling up toward . Direction makes physical sense. ✓


  1. Forward. . . Why: removes ; each step sees only its own input.
  2. .
  3. . Why: the future-loss channel is physically severed; memory of step 2's error cannot reach step 1.
  4. Weight gradient. . .

Verify: the gradient w.r.t. is non-zero even though — that is correct! The gradient measures the effect of turning the link on, i.e. still multiplies into the weight slot (). A zero weight is not a zero derivative. ✓


Cell E — saturation kills the gradient

  1. Forward. . . Why: large pre-activations push onto its flat tails.
  2. .
  3. Gate at step 2: . . Why: the future term is crushed to because the gate is nearly zero.
  4. Weight gradient. . .

Verify: gradient , essentially zero despite a real loss — saturation ⇒ dead gradient. This is why LSTMs and GRUs add un-squashed carry paths. ✓


Cell F — negative target, negative gradient

  1. Forward (same weights/inputs as Ex 1): , .
  2. .
  3. . Why: the mismatch is now huge ( locally), and the future term adds more.
  4. Weight gradient. . .

Verify: far larger than Ex 1's (bigger error ⇒ bigger gradient), and positive, so descent lowers -driven output toward the negative targets. Consistent. ✓


Cell G — a real-world word problem

  1. Read the story into numbers. Inputs ; targets . Why: the word problem is just Ex-1 machinery with new .
  2. Forward. . . Why: the cold input drags the memory below zero — the "mood" cooled.
  3. Backward. . . .
  4. Weight gradient. . . .

Verify: negative gradient ⇒ descent raises , letting yesterday's warmth carry more strongly so climbs toward the neutral target instead of overshooting negative. Story-consistent. ✓


Cell H — exam twist: full 3-step chain

  1. Forward. . . .
  2. . . Why: newest step, no future.
  3. . . .
  4. . . . Why: already carries step-3's loss, so passing it back gives its share of all three losses.
  5. Weight gradient. , , . .

Verify: with only the last two terms survive; both positive and comparable, giving . Each backward hop shrank the future term () — a live preview of why very long sequences lose signal. ✓


Recall Self-test: predict before you compute

If , is necessarily zero? ::: No — the incoming memory still multiplies the weight slot; a zero weight has a non-zero derivative (Ex 4 gave ). Which factor turns a live loss into a nearly-dead gradient? ::: The saturation gate when (Ex 5). When does the future term make smaller than its local part? ::: When or is negative, so the future contribution subtracts (Ex 3, Ex 7). Why must the weight gradient use and not ? ::: Because feeds the pre-activation; you must pass back through , whose slope is — skipping it doubled the answer in Ex 1.

Related: 3.5.01-Recurrent-Neural-Networks-RNNs · 2.2.03-Backpropagation-Algorithm · 3.5.03-Vanishing-and-Exploding-Gradients · 3.5.07-Bidirectional-RNNs.