Vanishing Gradients › Eigenvalue Analysis: Why Products of Matrices Shrink or Explode
Language AI HandbookAll chapters Vanishing Gradients › Eigenvalue Analysis: Why Products of Matrices Shrink or ExplodeOne section · Sections in this chapter3 / 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
The behavior of a matrix product depends critically on the spectral properties of each factor. Let's analyze what happens when you repeatedly multiply similar matrices together.
Consider a simplified version where is a scalar weight (or, more precisely, where we track the behavior along the dominant eigenvalue direction). Each factor in the gradient product contributes a scaling of approximately , where denotes the largest singular value and is the diagonal scaling matrix from the nonlinearity.
Since for all (the tanh derivative is at most 1, achieved at ), and in practice the hidden states often saturate the tanh function, contributes factors strictly less than 1.
The gradient product norm satisfies:
where is the maximum gain from the nonlinearity across all timesteps.
This inequality has two regimes:
- If , the product shrinks exponentially in . This is the vanishing gradient regime.
- If , the product grows exponentially. This is the exploding gradient regime.
The boundary between the two is the unit circle in eigenvalue space. Practical networks almost always fall into the vanishing regime because the tanh nonlinearity enforces , and weight matrices are initialized to have spectral radius near or below 1 for stability.
The spectral radius of a matrix is the largest absolute eigenvalue: . For a product of matrices to avoid exponential decay, the spectral radius of each factor must be at or above 1. With tanh nonlinearities constraining , this is almost impossible to achieve in practice across a long sequence.
What the Eigenvalue Decomposition Reveals
To understand the behavior of the gradient product more deeply, it helps to think about the eigenvalue decomposition of . Suppose is diagonalizable with eigenvalues , sorted by absolute value so that .
When you multiply the matrix by itself many times, the eigenvectors associated with large eigenvalues dominate the product. For a matrix power , the contribution from the -th eigendirection scales as . For directions where , the product collapses exponentially. For directions where , the product grows exponentially.
In the gradient product, the situation is analogous but more complex because each factor also includes the diagonal scaling from the nonlinearity. Nevertheless, the dominant behavior is determined by the spectrum of . The gradient signal propagates reliably only through eigendirections with eigenvalue magnitude near or above 1. All other directions lose information exponentially fast.
This has a subtle but important consequence for what RNNs can remember. The information that survives long backward passes is not arbitrary: it is precisely the information aligned with the dominant eigenvectors of . The recurrent weight matrix effectively selects which aspects of the hidden state are memorable and which are forgettable based purely on its spectral structure, not based on what the task requires. This spectral selectivity is one reason vanilla RNNs are difficult to reason about and hard to train for specific long-range tasks.
The Sigmoid Nonlinearity Makes Things Worse
While the analysis above uses tanh, the original LSTM paper and many early RNNs used sigmoid activations in some layers. Sigmoid is even more problematic for gradient flow.
The sigmoid function has a maximum derivative of , occurring at :
where:
- is the sigmoid output, always in
- is the complement, also in
- Their product is maximized when , giving
This means each sigmoid gate contributes at most a factor of to the gradient. A chain of 10 sigmoid layers multiplies the gradient by at most . Over 100 timesteps, the gradient magnitude is bounded by , which is effectively zero in floating-point arithmetic.
Tanh has a maximum derivative of 1 (at ), so it is somewhat better, but the maximum is only achieved exactly at zero. In practice, hidden states drift away from zero as the network processes sequences, and the effective gain drops well below 1.
A saturating nonlinearity is one where the derivative approaches zero as the input magnitude grows. Both tanh and sigmoid saturate: tanh approaches plus or minus 1 with near-zero slope for large , and sigmoid approaches 0 or 1 with near-zero slope. When hidden states are pushed into saturated regions, they contribute near-zero factors to the gradient product, accelerating vanishing.
To appreciate the interplay between saturation and vanishing gradients, consider what happens during the forward pass of a long sequence. At each step, the network computes a new hidden state and passes it through tanh. If the inputs are informative and the network is responding strongly, the pre-activation values will have large magnitudes, and tanh will saturate them to values near . This saturation is desirable from a representational standpoint: it allows the network to make confident decisions about whether information is present. But the same saturation that makes the forward representation less brittle makes the backward gradient fragile. A hidden state near has a derivative near zero, contributing nearly zero gain to the gradient product at that step. The very steps where the network is most confident about its representation are the steps that contribute most to gradient decay.
This creates a fundamental tension. Informative hidden states tend to saturate, which kills gradient flow. Unsaturated hidden states near zero have maximum gradient flow, but they also represent uncertain, low-magnitude activations. The network cannot simultaneously have rich, confident representations and efficient gradient flow when using saturating nonlinearities.