Sequence Models · Intermediate

Long Short-Term Memory

See exactly what gated cell memory adds beyond a plain RNN.

LSTM is kept on its own page so students can inspect every gate and cell-state update without mixing it into the RNN lesson.

Step by step

  1. Calculate forget gate.
  2. Calculate input gate and candidate content.
  3. Update cell state.
  4. Calculate output gate and hidden state.
  5. Predict from the final hidden state.
  6. Backpropagate through gates and cell memory.

Core formulas

Cell state

cₜ = fₜcₜ₋₁ + iₜgₜ

Gates control what memory is retained and written.

Hidden state

hₜ = oₜ tanh(cₜ)

The output gate controls exposed memory.

When to use Long Short-Term Memory

  • Learning gated recurrent memory.

Official documentation

TensorFlow RNN/LSTM guide