LSTM Gate Equations › The Hidden State Computation
Language AI HandbookAll chapters LSTM Gate Equations › The Hidden State ComputationOne section · Sections in this chapter8 / 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 final step converts the internal cell state into the external hidden state. This hidden state serves dual purposes: it becomes the LSTM's output for later processing (feeding into the next layer or making predictions), and it provides the recurrent context for the next time step.
The Hidden State Formula
The hidden state is computed by filtering the normalized cell state through the output gate:
where:
- : the new hidden state, the LSTM's output at this time step
- : the output gate activation (values between 0 and 1)
- : the cell state squashed to the range
Why Apply tanh to the Cell State?
Notice that we apply to the cell state before gating. This serves two important purposes:
1. Normalization: The cell state can accumulate values well outside through repeated additions. If the forget gate stays near 1 and the input gate keeps adding positive values, the cell state could grow to 10, 100, or larger. Applying compresses these potentially large values back into a bounded range, preventing the hidden state from exploding.
2. Consistency: The hidden state feeds into subsequent layers and provides recurrent context. Having it bounded in makes the network's behavior more predictable and stable. Downstream layers can rely on receiving inputs within a consistent range.
The cell state can accumulate values outside through repeated updates. Applying before the output gate ensures the hidden state remains bounded, improving numerical stability and gradient flow.
The Complete Picture
With the hidden state computed, we've completed one full LSTM step. The hidden state now flows in two directions:
- Forward to the next layer (or to the output): providing the LSTM's representation of the sequence up to time
- Recurrently to the next time step: serving as when processing
Meanwhile, the cell state flows only recurrently, carrying the LSTM's long-term memory forward without being directly exposed to downstream processing. This dual-track architecture, with the cell state as a protected memory channel and the hidden state as a filtered output, is what gives LSTMs their ability to capture long-range dependencies.