3.5.3 · D1Sequence Models

Foundations — Vanishing gradients in RNNs

1,688 words8 min readBack to topic

This page builds every symbol used in Vanishing gradients in RNNs from nothing. If you have never seen , , a derivative, or before, start at line one and do not skip.


1. A sequence and its time index

Figure — Vanishing gradients in RNNs

The picture shows a row of boxes left-to-right. Each box is one time step. The topic constantly says things like "many time steps ago" — that just means a box far to the left of the current one. The gap between two positions is written , the number of steps between step and the final step .


2. Vectors, and the bold-ish letters ,

Figure — Vanishing gradients in RNNs

Left figure: a single dot on a number line = one number (a scalar). Right figure: an arrow / column of stacked cells = a vector, a bundle of numbers travelling together.

Why the topic needs it: the whole problem is that information in (like "the subject was singular") must survive from an early step to a late one. If the memory-to-memory link is weak, that fact is lost.


3. Weights , and what a matrix does

The double subscript reads right-to-left: maps to ; maps to .

Figure — Vanishing gradients in RNNs

The figure shows a small arrow being turned into a longer, rotated arrow by "multiply by ". The key thing to feel: multiplying by the same over and over either keeps stretching (arrows grow) or keeps shrinking (arrows collapse). That repeated stretch/shrink is the seed of both exploding and vanishing gradients.

See Backpropagation Through Time for where these weights are updated.


4. The activation — a squashing function

Figure — Vanishing gradients in RNNs

Notice the flat tails in the figure. When is large the curve is nearly flat — moving barely changes the output. "Flat" is the villain of the next section.


5. The derivative — "how steep is the curve here?"

Why this tool and not another? Learning means adjusting knobs to reduce error. To know which way to turn a knob, we need "if I change this input a little, does the error go up or down, and how fast?" — that is the derivative. No other tool answers the sensitivity question.

Figure — Vanishing gradients in RNNs

The figure overlays (top) with its derivative (bottom, a hump).

This single fact — the multiplier is between 0 and 1 — is what makes the tanh factor a shrinking factor in the topic.


6. The chain rule — passing the signal hand-to-hand

Figure — Vanishing gradients in RNNs

The picture is a relay race: the baton (the gradient signal) passes . Each handoff multiplies by that step's local sensitivity. Multiplying many numbers, each below 1, drives the total toward zero. That is vanishing gradients in one sentence.

Why the topic needs the chain rule: the loss lives at the end () but the parameters live at every step. The chain rule is the only bridge that carries blame from the end back to the beginning.


7. The product symbol and the norm

Key rule the topic leans on: — the size of a product is at most the product of sizes. This lets us bound a scary product by simple powers.


8. Exponential decay

That collapse is exactly why plain RNNs fail on long dependencies, and why LSTM Architecture, GRU Architecture, Residual Connections and Attention Mechanisms were invented to give the gradient a shortcut.


Prerequisite map

Sequence and time index t

Vectors x_t and hidden state h_t

Weight matrix W times a vector

tanh squashing activation

Derivative equals slope

Chain rule as a relay

Norm and spectral norm of W

Product symbol over time steps

Exponential decay gamma to the T minus t

Vanishing gradients in RNNs


Equipment checklist

What does the index label?
The position (time step) of an input in an ordered sequence.
What is in plain words?
The RNN's memory vector at step — a summary of all it has read so far.
What does multiplying a vector by do?
Stretches, rotates and reshapes it; repeated use keeps growing or shrinking arrows.
What range does squash inputs into?
Between and .
What question does a derivative answer?
"If I nudge the input a tiny bit, how much does the output move?" — the slope.
What is the maximum value of , and where?
, at ; it only shrinks a signal, never grows it.
State the chain rule in words.
Total sensitivity of to equals the product of the step-by-step sensitivities along the path.
What does mean?
Multiply all the listed terms together as runs from to .
What does the spectral norm measure?
The largest factor by which can stretch any vector.
Why does with cause vanishing?
Multiplying a below-one number by itself many times shrinks it exponentially toward zero.