LSTM Gate Equations › The Hidden State Computation

Michael BrenndoerferUpdated May 11, 20252 min read
Language AI HandbookAll chapters
Part 11 of 67Recurrent Neural Networks
Chapter 78LSTM Gate Equations › The Hidden State Computation
Reading section 8 of 17 · The Hidden State Computation · 2 minSection 8 of 17 · 2 min

Book contents

Section 8 of 17 · 2 min read

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:

ht=ot⊙tanh⁡(ct)\mathbf{h}_t = \mathbf{o}_t \odot \tanh(\mathbf{c}_t)

where:

  • ht∈Rh\mathbf{h}_t \in \mathbb{R}^h: the new hidden state, the LSTM's output at this time step
  • ot∈Rh\mathbf{o}_t \in \mathbb{R}^h: the output gate activation (values between 0 and 1)
  • tanh⁡(ct)\tanh(\mathbf{c}_t): the cell state squashed to the range (−1,1)(-1, 1)

Why Apply tanh to the Cell State?

Notice that we apply tanh⁡\tanh to the cell state before gating. This serves two important purposes:

1. Normalization: The cell state can accumulate values well outside [−1,1][-1, 1] 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 tanh⁡\tanh 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 (−1,1)(-1, 1) makes the network's behavior more predictable and stable. Downstream layers can rely on receiving inputs within a consistent range.

Why Apply tanh to the Cell State?

The cell state can accumulate values outside [−1,1][-1, 1] through repeated updates. Applying tanh⁡\tanh 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 ht\mathbf{h}_t now flows in two directions:

  1. Forward to the next layer (or to the output): providing the LSTM's representation of the sequence up to time tt
  2. Recurrently to the next time step: serving as ht−1\mathbf{h}_{t-1} when processing xt+1\mathbf{x}_{t+1}

Meanwhile, the cell state ct\mathbf{c}_t 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.