LSTM Gradient Flow › The Residual Connection Analogy
Language AI HandbookAll chapters LSTM Gradient Flow › The Residual Connection AnalogyOne section · Sections in this chapter9 / 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
Understanding the LSTM cell state gradient path is greatly aided by comparing it to residual networks (ResNets), introduced by He et al. (2016). The two architectures solve the same fundamental problem using the same mathematical trick: creating an additive shortcut for gradient flow.
How ResNets Work
In a standard deep network, each layer transforms its input: where includes weight matrices and nonlinearities. During backpropagation, the gradient through such layers involves a product of Jacobians, which can vanish.
ResNets add a skip connection: . Now the gradient is:
The identity matrix ensures that even if the network learns (effectively turning off the learned transformation), the gradient still flows backward with magnitude 1. The addition creates a guaranteed gradient highway.
The Parallel
The LSTM cell state update:
is structurally analogous to the ResNet update:
In both cases, the output is the sum of the input (scaled by a gate in the LSTM case, or passed through unchanged in ResNet) plus a learned transformation. In both cases, the gradient of the output with respect to the input contains a term that doesn't pass through the learned transformation.
The key difference is that the LSTM's skip connection is learnable (the forget gate scales the cell state), while ResNet's skip connection passes the input unchanged. The LSTM therefore has more flexibility: it can open or close the gradient highway depending on what it has learned, while ResNet always keeps the highway fully open.
This difference has tradeoffs. ResNet's unconditional skip connection guarantees gradient flow without any training: even an untrained ResNet has a clear gradient path. The LSTM's gated skip connection needs to be learned into the "open" position before it starts helping. This is one reason why forget gate bias initialization matters so much for LSTMs: it puts the gate in an approximately "open" position before training starts, mimicking the ResNet's unconditional highway.
Implications for Architecture Design
This analogy clarifies why the cell state is the "memory" component and the hidden state is the "communication" component. The cell state is the gradient highway, designed for long-range information storage. The hidden state is exposed to the outside world (fed to output layers, used by attention mechanisms, passed to the next layer), but it is more "narrow" in gradient flow because it passes through additional nonlinearities.
Later architectures like the GRU (which we'll explore in the next chapter) and Transformer architectures incorporate the residual connection insight even more directly. Transformers use explicit skip connections between every sublayer. This ensures that gradient flow is guaranteed at every depth level. In a sense, the LSTM's cell state foreshadowed this design pattern: create an additive path that bypasses the heavy computations so that gradient can flow freely. The progression from LSTM to ResNet to Transformer represents an evolution in how clearly and explicitly this design principle is applied.