What is LSTM (Long Short-Term Memory)?
LSTM is a type of recurrent neural network that uses input, forget and output gates plus a separate cell state to carry information across long sequences without losing it.
It differs from a standard recurrent neural network in its gates: a standard RNN rewrites its state at each step and quickly forgets the distant past, while an LSTM uses gates to control what is kept, forgotten and read. Gated Recurrent Unit applies the same idea more simply with two gates.
- Topic
- Machine learning, models and training
- Also known as
- Long short-term memory
- Origin
- 1997, Hochreiter and Schmidhuber; forget gate 2000, Gers et al.
How LSTM (Long Short-Term Memory) works
- The cell state is an information line that flows across steps with little change, which greatly eases vanishing gradients; exploding gradients are usually handled with gradient clipping.
- The forget gate decides what to erase from the previous cell state.
- The input gate sets how much new information is added to the cell state.
- The output gate chooses which part of the cell state becomes that step's hidden state.
In more detail
Gates and the additive cell-state update
At each step, the new cell state is the old state scaled by the forget gate plus the candidate state scaled by the input gate; the output gate then filters the tanh of the cell state to produce the hidden state. This additive update, rather than repeated matrix multiplication, is why memory persists over many steps.
No training parallelism, constant inference memory
While Transformer inference grows quadratically or requires a growing KV cache over sequence length, an LSTM processes each step in O(1) memory and linear time O(T). However, because step t depends on step t−1, classic LSTM training cannot be parallelised across sequence tokens like a Transformer.
Bidirectional and unidirectional LSTMs
A bidirectional LSTM (BiLSTM) reads a sequence both forward and backward, combining past and future context when the entire sequence is available (such as offline text tagging or log analysis). For real-time streaming where future steps are unseen, only unidirectional LSTMs can be used.
Why LSTM (Long Short-Term Memory) matters for on-premises AI
Before Transformers, LSTMs were the core architecture for machine translation, speech recognition and text classification. Classic LSTMs are absent from mainstream large language models (xLSTM revives the gated-memory idea) yet still serve as a small, fast option for time series tasks such as transaction sequences, sensor readings and network traffic. In-house they run on real-time streaming data at low hardware cost.
A telecom operator monitors traffic readings from base stations with an LSTM-based model and sends stations that deviate from the expected pattern as alerts to its in-house network operations centre.
Common questions
What is the difference between LSTM and GRU?
LSTM uses three gates and a separate cell state. GRU has fewer parameters with two gates and gives similar results on many tasks.
How does LSTM differ from a Transformer?
An LSTM reads the sequence in order and carries the past in a state vector. A Transformer attends to the whole sequence at once; trained in parallel, it is more efficient at scale.
Related terms
- Recurrent neural network
- Gated Recurrent Unit
- Time series forecasting
- Transformer
- Deep learning
- Backpropagation
Sources
- Hochreiter and Schmidhuber, Long Short-Term Memory, 1997
- Goodfellow, Bengio and Courville, Deep Learning, 2016
In the glossary: Glossary, E to L