LSTM Gradient Flow › The Constant Error Carousel
Language AI HandbookAll chapters LSTM Gradient Flow › The Constant Error CarouselOne section · Sections in this chapter2 / 17 ↓
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 vanishing gradient problem in vanilla RNNs arises because every step of backpropagation through time multiplies by both a weight matrix and an activation function derivative. Over many timesteps, these repeated multiplications compound, and gradients shrink exponentially toward zero. The LSTM sidesteps this by creating a path where gradients can flow with far fewer multiplicative barriers.
Recall the Vanilla RNN Gradient Problem
To understand why the LSTM solution is elegant, we first need to recall why vanilla RNNs fail. As we derived in the Backpropagation Through Time and Vanishing Gradients chapters, the gradient of the loss with respect to the hidden state at an earlier timestep , when the loss is computed at timestep , involves a product of Jacobians:
where each local Jacobian is:
where:
- : the pre-activation at timestep
- : a diagonal matrix of elementwise derivatives, all values between 0 and 1
- : the recurrent weight matrix
The product of such matrices, each with spectral norm typically less than 1 (because and we need for stable training), drives the gradient toward zero exponentially in . For sequences of length 100 or more, gradients can shrink to or smaller, making them numerically meaningless.
This practical inconvenience creates a fundamental barrier to learning. The optimizer receives near-zero gradient signals for parameters that affect early timesteps, so those parameters barely update. The network is effectively blind to its own behavior at the beginning of a sequence, no matter how many training examples you throw at it. Increasing the learning rate doesn't help; it only amplifies the near-zero signals into slightly larger near-zero signals, or risks blowing up the hidden state path entirely. The problem is architectural rather than a tuning issue.
The Cell State: An Additive Highway
The LSTM cell state update equation is:
where:
- : the cell state at timestep
- : the forget gate activations (values in )
- : the cell state from the previous timestep
- : the input gate activations
- : the candidate cell state
- : element-wise (Hadamard) multiplication
This update has two critical structural properties. First, it is additive: the new cell state is the old cell state scaled by plus a new term. Second, the previous cell state passes through only an element-wise multiplication, not a full matrix multiplication. There is no multiplying the cell state as it travels through time.
Now consider the gradient of the loss with respect to the cell state at an earlier timestep. Using the chain rule through the cell state pathway only:
where:
- : the loss gradient at the final timestep
- : the element-wise product of forget gate values from to
Each element of this product is a product of values from the forget gate, all in . Unlike the vanilla RNN, there is no weight matrix and no nonlinearity derivative in this path. The only multiplicative factor is the forget gate activations.
The constant error carousel refers to the cell state's ability to carry gradients across time with only element-wise scaling by the forget gate, rather than the repeated matrix multiplications and nonlinearity derivatives that crush gradients in vanilla RNNs. If forget gate values are close to 1, gradients flow nearly unchanged through the cell state pathway.
Why "Constant Error"?
The name "constant error carousel" was chosen deliberately. In the original paper, Hochreiter and Schmidhuber showed that if the forget gate produces a value of exactly 1 for some dimension, the gradient of that dimension is preserved exactly from one timestep to the next: a constant error signal circling in the carousel of time without decay. In practice, gates are never exactly 1, but they can be close enough that useful gradient signal survives hundreds of timesteps, something impossible for vanilla RNNs.
The word "carousel" is also apt. Imagine a merry-go-round that keeps spinning without friction. Each time the error (gradient) passes a given point in time, it arrives with the same magnitude it had before. There's no damping mechanism, no weight matrix to shrink it, no nonlinearity to saturate it. When forget gates are near 1, the LSTM approximates this frictionless carousel. When forget gates are near 0, the carousel stops, and gradients from earlier times can no longer reach the current position. The LSTM thus gives the network explicit control over whether the carousel continues spinning in any given dimension.
The 1997 paper was remarkable for its time because it took the vanishing gradient problem seriously as a mathematical obstacle rather than an empirical nuisance. Hochreiter had already identified the problem in his 1991 diploma thesis, and the LSTM was his principled architectural response. Understanding this history helps you appreciate that the constant error carousel is not an accident or an empirical observation; it's a deliberate design goal, baked into the architecture from the start.