# Long short-term memory (LSTM)

> Canonical: https://skillalmanac.com/glossary/lstm | Last verified: 2026-11-25 | Index status: index-eligible

Long short-term memory (LSTM) is a type of recurrent neural network built to learn dependencies across long sequences. It keeps a running memory, called the cell state, and uses learned gates to decide what to add, keep and output.

Also called: LSTM, long short term memory, LSTM network, LSTM model, LSTM networks, LSTM neural network.

## In plain language

A plain recurrent network reads a sentence one word at a time and carries a short summary forward, but the summary tends to lose early details by the end of a long passage. An LSTM adds a separate memory lane and three small controls, called gates, that learn when to write something into memory, when to forget it and when to let it influence the output. That made it a common choice for text, speech and sensor data before transformers took over many of those jobs. It still reads one step after another, while transformer training can parallelise positions; actual speed depends on the model, sequence and hardware, and its memory is finite.

## Technical definition

An LSTM cell keeps a cell state alongside the hidden state. Per IBM's description, a forget gate multiplies the previous cell state by a value between 0 and 1, an input gate scales a candidate cell state using a sigmoid, and an output gate decides which part of the updated cell state is exposed. IBM notes that the cell's self-connected recurrent edge of fixed weight 1 helps gradients pass across many time steps, which addresses the vanishing gradient problem that stalls training in plain recurrent networks. Colah's tutorial describes the same three gates regulating the cell state. Training uses backpropagation through time.

## How it shows up when you use agents

An LSTM can appear when a coding agent helps maintain, retrain or replace a sequence-model project. For comparison, the original [Transformer](/glossary/transformer) architecture permits parallel processing of training positions with attention; its autoregressive decoder uses a causal mask and generates outputs sequentially. The architecture used by a coding product must be checked in that product's documentation.

What breaks when the term is misunderstood: people assume that "memory" in LSTM is the same as the memory an agent keeps between sessions. It is not. The hidden and cell states can be supplied to a later LSTM call; PyTorch defaults them to zeros only when they are omitted. An agent that needs to remember a past conversation uses a file, a database or the [context window](/glossary/context-window), not an LSTM cell.

A practical next step if you inherit an LSTM project: check that the train and test split respects time order, then compare against a simpler baseline before deciding to keep it. The catalogue has no training skills, so use [split-leakage-check](/skills/skill-almanac/split-leakage-check) for the data side only.

## Common confusions

- **LSTM versus RNN.** An LSTM is one kind of [recurrent neural network](/glossary/recurrent-neural-network). It adds a cell state and gates to the plain recurrent design so it can learn longer dependencies.
- **LSTM versus transformer.** Both model sequences. An LSTM processes steps in order and carries state forward. Transformer training can process positions in parallel, but decoder causal masks restrict attention and autoregressive generation proceeds token by token.
- **Myth: an LSTM remembers without limit.** The gates learn what to keep, but the memory is a fixed-size vector and information can still be lost.
- **LSTM memory versus agent memory.** The cell state is recurrent model state and can be carried between sequence chunks. [Agent memory](/glossary/agent-memory) is stored outside the model and reloaded.

## Worked examples in this catalogue

### [What Is an LLM? The Facts Agent Users Need](https://skillalmanac.com/learn/what-is-an-llm-for-agent-users)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: An explanation of what a large language model is for people who run agents, written for users rather than for machine-learning engineers.

Why it exercises the concept: The guide's Transformer and BERT examples contrast with an LSTM's recurrent state.

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Checks train, validation and test files for duplicates, shared groups, time and label leakage; prints JSON.

Why it exercises the concept: LSTMs are often trained on time-ordered data, where time leakage between train and test files is a real risk. The catalogue has no training skills, so this is a contrast case that checks data, not a model.

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A fixed exploratory-analysis procedure and CSV profiler that keeps findings descriptive, evidenced and caveated.

Why it exercises the concept: Sequence data should be profiled before a recurrent model is trained on it. This skill profiles a CSV and does not build an LSTM.

## Related terms

- [Recurrent neural network (RNN)](https://skillalmanac.com/glossary/recurrent-neural-network.md)
- [Neural network](https://skillalmanac.com/glossary/neural-network.md)
- [Deep learning](https://skillalmanac.com/glossary/deep-learning.md)
- [Transformer](https://skillalmanac.com/glossary/transformer.md)
- [Natural language processing (NLP)](https://skillalmanac.com/glossary/natural-language-processing.md)
- [Backpropagation](https://skillalmanac.com/glossary/backpropagation.md)

## Sources

- [What is Long Short-term Memory (LSTM)?](https://www.ibm.com/think/topics/lstm), IBM (accessed 2026-11-24)
- [Understanding LSTM Networks](https://colah.github.io/posts/2015-08-Understanding-LSTMs/), colah's blog (accessed 2026-11-24)
- [torch.nn.LSTM (PyTorch 2.9)](https://docs.pytorch.org/docs/2.9/generated/torch.nn.LSTM.html), PyTorch (accessed 2026-11-25)
- [Attention Is All You Need](https://arxiv.org/html/1706.03762v7), Vaswani et al. (arXiv) (accessed 2026-11-25)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
