Vanishing Gradients › The Gradient Product Problem
Language AI HandbookAll chapters Vanishing Gradients › The Gradient Product ProblemOne section · Sections in this chapter2 / 18 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To train an RNN, we need to compute how the loss at time depends on the hidden state at some earlier time . This is exactly the gradient , where is the loss at the final timestep and is the hidden state at time .
Recall from the BPTT derivation that the hidden state evolves as:
where:
- is the hidden state vector at time
- is the recurrent weight matrix
- maps input to the hidden layer
- is the bias
Applying the chain rule, the gradient of with respect to involves all intermediate steps:
where each factor in the product is the Jacobian matrix:
where:
- is the pre-activation at step
- is the element-wise derivative of tanh evaluated at
- is the diagonal Jacobian of the tanh nonlinearity
So the full gradient becomes:
This is a product of matrices. When is large, this product determines whether learning succeeds or fails.
To understand why this product is dangerous, think about what it represents physically. Each factor is a local linear approximation to how perturbations to propagate to . Multiplying these local approximations together gives the global sensitivity: how much does a small change to affect ? The answer, for long sequences, is almost always: very little. The product of many factors smaller than one collapses to zero.
The Chain Rule Imposes a Product Structure
It is worth pausing to understand why the chain rule produces this particular structure and why there is no way around it within the RNN formulation. The chain rule is not a choice or an approximation: it is the exact rule for computing how composed functions depend on their inputs. The RNN is a composed function. depends on , which depends on , all the way back to . The gradient of this chain of compositions is exactly the product of the local derivatives.
This means the vanishing gradient problem is not a bug in the BPTT algorithm or a consequence of a bad implementation. It is built into the structure of the RNN itself. The recurrence relation that makes RNNs powerful at processing sequences is also the source of the gradient problem. You cannot have sequential composition without a multiplicative gradient chain.
The only escape is to change the recurrence relation itself, which is precisely what LSTM does. Rather than composing a function at every timestep (multiplying), the LSTM adds to a memory cell. Addition distributes gradient flow uniformly backward, as we will see in the LSTM chapter.