Walk me from RNNs to LSTMs to transformers. Why did attention win?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
An RNN carries a hidden state forward: h_t = f(h_{t-1}, x_t). Training backpropagates through time, which multiplies the same Jacobian once per step, so gradients vanish or explode over long ranges and the practical memory is short.
Full worked answer
An RNN carries a hidden state forward: h_t = f(h_{t-1}, x_t). Training backpropagates through time, which multiplies the same Jacobian once per step, so gradients vanish or explode over long ranges and the practical memory is short.
LSTM fixes the gradient path, not the parallelism. It adds a cell state updated additively, gated by forget/input/output gates. The additive path is the same trick as a residual connection: gradient flows through it without repeated multiplication, so an LSTM holds context over hundreds of steps rather than tens. GRU is a cheaper two-gate variant with similar behaviour.
Two problems survived. First, everything about the past has to be squeezed into a fixed-size hidden state, which is exactly the bottleneck attention was originally invented to relieve, as a bolt-on to seq2seq RNNs. Second, and decisively, recurrence is sequential in time, so you cannot parallelize training across positions.
Transformers drop recurrence entirely. Every position attends to every other, so the path between any two tokens is O(1) instead of O(n), and training becomes large matmuls that saturate GPUs. The costs: attention is O(n²) in compute and memory versus O(n) for an RNN, and it is permutation-equivariant, so order has to be injected via positional encodings (RoPE is the current default).
So the honest answer to "why did attention win" is hardware utilisation plus gradient path length, not some abstract superiority. Given the same FLOPs you could train on vastly more data.
Worth noting the wheel is turning back: state-space and linear-attention models (Mamba-style) recover an O(n) recurrent formulation that still parallelizes at train time via a scan, and hybrid attention/SSM stacks ship in production models for long context. And an autoregressive transformer at inference with a KV cache is a recurrence, just with a state that grows with the sequence.
What a good answer covers
- An RNN carries a hidden state forward: h_t = f(h_{t-1}, x_t)
- Training backpropagates through time, which multiplies the same Jacobian once per step, so gradients…
- LSTM fixes the gradient path, not the parallelism
- It adds a cell state updated additively, gated by forget/input/output gates
- The additive path is the same trick as a residual connection
Key terms: LSTM · recurrence is sequential in time
In the glossary: Attention · RoPE · Mamba / SSM · KV cache
Interviewer follow-ups to expect
If the KV cache makes decoding recurrent anyway, where does the transformer's advantage actually show up?
Why does the LSTM's additive cell state help gradients when the gates themselves are multiplicative?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep