Worked examples — Limitations of RNNs motivating transformers
This is the hands-on companion to the parent note. There we argued why RNNs struggle; here we compute the failure in every scenario it can appear. Nothing new is assumed — every symbol is rebuilt as it enters.
Before we start, three tiny reminders (each is a picture you should hold in your head):
One more symbol before the formula: = the number of boxes (hand-offs) the gradient must cross to get from where it starts to where it lands. Picture counting the red arrows between two boxes; is how many arrows you pass through.
The one formula that powers almost everything below:
The figure below makes this concrete: the outlined bars are the original strength at each box, the filled blue bars are what actually survives after each red "" hand-off, and the yellow numbers are for . Watch the blue bar shrink one hand-off at a time — that shrinking is the vanishing gradient.

The scenario matrix
Every question this topic can throw at you lives in exactly one of these cells. The worked examples afterward are labelled by cell, and together they hit all of them.
| Cell | Regime / input | What decides it | Example |
|---|---|---|---|
| A | — vanishing | many boxes, leaky bucket | Ex 1 |
| B | — exploding | many boxes, overflowing bucket | Ex 2 |
| C | — the knife-edge | perfect preservation | Ex 3 |
| D0 | Degenerate: | dead weights, one-step wipeout | Ex 4 |
| D1 | Degenerate: | only one box, no chain at all | Ex 5 |
| E | Limiting: | what happens to as grows without bound | Ex 6 |
| F | Parallel-time cost | sequential vs parallel | Ex 7 |
| G | Real-world word problem | translate a story into , , | Ex 8 |
| H | LSTM partial-fix | forget gate replaces | Ex 9 |
| I | Exam twist: bottleneck bits | information capacity vs demand | Ex 10 |
Prerequisites you can revisit if a step feels shaky: Vanishing and Exploding Gradients, Backpropagation Through Time, Computational Complexity of Sequence Models, LSTMs and GRUs, Encoder-Decoder Architecture.
Example 1 — Cell A: the vanishing case
-
Identify the numbers. , , . Why this step? Every gradient problem reduces to plugging into . First we must know which number is which — a wrong assignment poisons everything.
-
Apply the power formula. Why this step? Each of the 100 boxes multiplies the signal by ; stacking 100 of them is the power (see the leaking-bucket figure).
-
Evaluate. . Why this step? We need an actual number to feel the size. A quick sanity anchor: , and steps is ten such blocks, so , which is tiny — consistent.
Answer: . The signal is about 170× weaker — practically gone. The RNN cannot learn that the far-away word mattered.
Recall Verify (sanity check)
Since and is large, must be a small positive number below . is small, positive, below . ✓ Units: gradients are dimensionless ratios, so a pure number is correct.
Example 2 — Cell B: the exploding case
-
Assign. , , . Why this step? Same machinery — only crossed the threshold , which flips leak into overflow.
-
Apply. . Why this step? 80 amplifications compound multiplicatively, exactly the same power structure, just with .
-
Evaluate. … let's be precise: . Why this step? We need magnitude. Anchor: , eight blocks give , which is in the thousands — consistent.
Answer: . The gradient blows up ~2000×; training diverges (loss becomes NaN). This is the exploding twin of vanishing — same formula, .
Recall Verify
, large ⇒ . . ✓ Note ; and indeed rounds to — checked in VERIFY.
Example 3 — Cell C: the knife-edge
- Assign. , .
- Apply. . Why this step? raised to any power is — the bucket neither leaks nor overflows.
- Answer: exactly .
Meaning: is the ideal the whole field chases. LSTMs try to sit near it with their cell-state "highway"; transformers sidestep the chain entirely so there is no to tune. See Vanishing and Exploding Gradients.
Recall Verify
. ✓ This is the boundary between Cells A () and B ().
Example 4 — Cell D0: degenerate dead weights,
-
One box. . Why this step? Multiplying by once annihilates the signal — the very first hand-off empties the bucket completely.
-
Many boxes. for every . Why this step? for any positive ; there is nothing left to keep multiplying, so extra boxes cannot make it "more zero."
-
Contrast with . Note the gradient within box 1 itself ( hops, ) is untouched; the wipeout only strikes the moment you try to reach an earlier box.
Answer: is the most extreme vanishing — total in a single step, not gradual. This is why practitioners initialize away from zero: dead recurrent weights sever the past instantly. It is the left endpoint of the whole -axis (Cell A is ; this is the boundary ).
Recall Verify
and , while (the / same-box case). ✓
Example 5 — Cell D1: degenerate single-step,
-
Sequential steps. With there is exactly one hidden state — nothing before it. Depth . Why this step? The bottleneck we complain about is the chain; with one link there is no chain.
-
Gradient hops. The gradient crosses boxes. Why this step? To reach from you cross zero boxes.
-
Apply. . Why this step? by the meaning of "multiply by nothing." The signal is untouched.
Answer: no vanishing, no exploding, perfect parallelizability (there is nothing to parallelize). RNNs are only bad on long sequences — the degenerate case exposes that the disease is length, not the recurrence itself. (Contrast with Cell D0: there the weights were dead; here the chain is trivially short.)
Recall Verify
for any (including ). So is immune. ✓
Example 6 — Cell E: the limit
-
Set up the limit. We study . Why this step? "Limiting behaviour" asks what value we approach, not any single .
-
Reason about the sign of . Since , . Then , and . Why this step? Writing a power as turns "repeated multiply" into "add up ", where the sign of decides the fate. This is exactly why the exponential tool appears — it converts multiplicative decay into additive slope.
-
Conclude. .
Answer: for every . No matter how gentle the leak, an infinitely long sentence loses all early-word gradient. Contrast the three regimes on the figure below.

Recall Verify
is astronomically small (underflows to in floating point). ✓ For the same limit is ; for it stays — all three plotted.
Example 7 — Cell F: sequential vs parallel wall-clock
-
RNN time. Sequential steps , each ms. Why this step? needs , so the 512 updates cannot overlap — they add up. This is the depth from Computational Complexity of Sequence Models.
-
Transformer time. All 512 positions computed in one parallel wave, so the depth is — say one ms wave (ignoring the parallel work each does). Why this step? Self-attention lets position 512 read position 1 directly, so there is no forced ordering. See Self-Attention Mechanism.
-
Speedup. . Why this step? Ratio of wall-clock times gives the practical win.
Answer: ~512× faster forward pass in this idealized model — matching " vs depth."
Recall Verify
ms; . ✓ Units: ms / ms = dimensionless speedup factor.
Example 8 — Cell G: real-world word problem
-
Count the hops from loss to "not". From position back to position is boxes. Why this step? The gradient must travel from where the loss is measured to where the important parameter lives. Distance = box count.
-
Apply. . Why this step? Same leaking bucket, now 295 hand-offs deep.
-
Evaluate. . Why this step? We need to see whether it is learnable. Anything below ~ is effectively drowned by numerical noise.
Answer: — the model essentially never learns that "not" flips the sentiment. Exactly the failure the parent note narrated, now a number.
Recall Verify
hops, ⇒ deeply tiny positive number. ✓ (checked below).
Example 9 — Cell H: the LSTM partial fix
- Vanilla baseline. From Ex 8: .
- LSTM version. Replace by : Why this step? The additive cell-state path makes the effective per-box multiplier the forget gate, not . Bigger multiplier ⇒ slower leak.
- Evaluate. . Why this step? We compare magnitudes: vs .
Answer: the LSTM keeps of the signal versus — about 170,000× stronger, yet still not . This is precisely the parent's point: LSTMs mitigate, they do not eliminate. Push to thousands and even .
Recall Verify
Ratio . ✓
Example 10 — Cell I: exam twist, information bottleneck
-
Bits available (honest upper bound). The vector has slots, each a -bit float, so the raw container holds at most Why this step? A float's storage is exactly its bit-width; of them is . This is a generous ceiling — real usable capacity is lower because floats waste bits on sign/exponent and because the network cannot exploit every bit pattern independently. We use the ceiling so our conclusion is conservative.
-
Bits required. Each token picks one of options: bits; tokens ⇒ . Why this step? Information to reconstruct the exact sequence is bits-per-token times number of tokens.
-
Compare. vs the ceiling . They are already the same order of magnitude — and the usable capacity is far below the ceiling, so in practice demand exceeds supply. Why this step? If even the generous ceiling barely clears the demand, the realistic (much smaller) capacity cannot store the sentence losslessly — the encoder must discard information. This is the compression bottleneck of Encoder-Decoder Architecture.
Answer: required bits sits right against the -bit storage ceiling, and effective capacity is well below that ceiling — so long inputs are compressed lossily and degrade. Attention fixes this by letting the decoder look back at all hidden states instead of one squeezed vector.
Recall Verify
; ; the two are within a factor of , confirming demand and the storage ceiling are the same order. ✓ Units: bits vs bits, dimensionless comparison.