To train a loop, unroll it. Run the forward pass, then send the gradient backwards through every timestep and watch the chain rule multiply.
Controls
Sequence length T5
The Chain Rule at Work
∂L/∂h₁ = ∂L/∂hₜ × ∏ ∂hₜ/∂hₜ₋₁
Product so far (factor 0.7 per step)
—
Every step back multiplies by ∂hₜ/∂hₜ₋₁ (≈ 0.7 here). Watch the product shrink as the gradient travels toward t = 1.
The Unrolled Network
IDLE
Narration
The same RNN cell, copied once per timestep. Press Run Forward Pass to feed the sequence through, left to right.
Gradient Magnitude Reaching Each Timestep
Backpropagation Through Time, Step by Step
How gradient descent trains a network that contains a loop.
The Problem With a Loop
Backpropagation works on feed-forward graphs — signals flow one way, gradients flow back the same way. An RNN's feedback loop breaks that picture. The fix, Backpropagation Through Time (BPTT), is beautifully blunt: unroll the loop into T copies of the cell, one per timestep, and the loop becomes an ordinary (deep) feed-forward chain that standard backprop can handle.
Forward, Then Backward
Forward pass: tokens enter left to right; each cell computes hₜ from xₜ and hₜ₋₁; the loss L is measured at the end.
Backward pass: the gradient ∂L/∂h starts at the loss and travels right to left. Crossing each cell multiplies it by the local derivative ∂hₜ/∂hₜ₋₁ — the chain rule, applied once per timestep.
Weight update: because every unrolled copy shares the same W and U, their gradient contributions from all timesteps are summed before the single weight update.
Interactive Exploration Guide
Run the forward pass. Cells light up green in sequence, ending at the loss node — this is the network "reading" the sentence.
Backpropagate. Amber arrows sweep right to left. Watch the chain-rule product in the sidebar: 1.0, then 0.7, then 0.49... each timestep multiplies again.
Set T = 7 and repeat. By the time the gradient reaches t = 1 it is 0.7⁶ ≈ 0.12 — barely a whisper. The bar chart makes the decay unmistakable. This shrinkage is the seed of the vanishing gradient problem, covered next.
Key Takeaway
BPTT = unroll the loop, backpropagate through the chain, sum the shared-weight gradients. It makes RNNs trainable — but it also chains together T multiplications, and a long product of numbers below 1 races toward zero. That arithmetic inevitability is the vanishing gradient problem.
Cheat sheet
Backpropagation Through Time
To train a loop, unroll it. Run the forward pass, then send the gradient backwards through every timestep and watch the chain rule multiply.