Why Did Transformers Replace RNNs and LSTMs?
Why transformers took over from RNNs and LSTMs for language work, what they cost, and how to explain the switch for your AI interview.
In short
Transformers replaced RNNs and LSTMs because they handle all the words in a passage at the same time during training, instead of one after another. That makes training faster on GPUs, and attention links two distant words in one step.
11 min readIntermediateVery common · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
RNNs and LSTMs read text one word at a time, so each step waits for the one before. That is slow on GPUs, and in a long document the early details fade. Transformers use attention, so every word can look at every other word in one step, and training runs in parallel. The price is that attention gets costlier as the text grows, so I would name that trade-off too.
Before 2017, most translation systems read text the way you read aloud: one word at a time, from left to right. An RNN, which stands for recurrent neural network, keeps a running memory and updates it at every word. An LSTM is a kind of RNN with gates that decide what to keep and what to drop, so it holds on to more. Both are slow to train, because each step has to wait for the one before it.
There are two problems. First, a GPU is built to do many things at once, and a chain of steps that must run in order cannot use that power well. Second, learning across a long text is hard. The learning signal has to travel back through many steps, and it gets weaker and can vanish. So a clause near the start of a long contract can be lost by the time the model reaches the end.
A transformer uses attention instead. Each word looks at every other word in the passage in one step, and the model learns which ones matter. All the words are handled together, so training runs in parallel. Google reported in 2017 that the Transformer could speed up training by up to an order of magnitude, and it beat the recurrent models on translation benchmarks.
The trade-off is cost. Attention compares every word with every other word, so the work grows fast as the text gets longer. A model can only look back over a limited amount of text, its context window. Generating an answer still produces one token at a time, so the parallel gain mostly helps training. So in an interview I would say transformers won on parallel training and direct links, and that they pay for it on long inputs.
What are RNNs, LSTMs and transformers, in plain words?
Picture a claims adjuster at an insurer reading a 15-page policy. One way is to read page by page, keeping a sticky note of what matters so far. The note gets crowded, and details from page 1 are smudged by page 15. The other way is to spread the whole policy on a desk and put any two clauses side by side. That is the difference between the two kinds of model.
An RNN (recurrent neural network) reads one word at a time and carries a running memory forward. An LSTM (long short-term memory) is an RNN with gates that control what it keeps. A transformer reads the whole passage and uses attention, so each word can look straight at the others.
Take a real case. An insurer's assistant has to answer a customer's question about a fee. The fee rule is in clause 1, and the answer depends on it in clause 40. The model has to connect two places that sit far apart in the text.
Key words
- RNN
- A network that reads a sequence one step at a time and carries a running memory forward.
- LSTM
- An RNN with gates that control what it keeps and drops, so it holds on to more.
- Transformer
- A network built on attention, with no step-by-step loop over the words.
- Attention
- A way for each word to weigh how much every other word matters to it.
- Parallel
- Doing many things at the same time, which GPUs are built for.
Why was reading one word at a time the problem?
Before 2017, RNNs were the usual choice for translation and other language tasks. The Google team that introduced the Transformer explained the catch, and the paper's authors gave the same reason.
“The sequential nature of RNNs also makes it more difficult to fully take advantage of modern fast computing devices such as TPUs and GPUs, which excel at parallel and not sequential processing.”
Google Research, 2017
“This inherently sequential nature precludes parallelization within training examples”
Vaswani and colleagues, 2017
The first problem is distance. Reading one word at a time forces many steps to link words far apart, and each step can lose a little of the earlier detail. The second is hardware. A GPU (the graphics chip that does many sums at once) is built for work that runs side by side, and a chain of steps has to run in order.
Linking clause 1 to clause 40
Fee rule, token 12
clause 1 of the policy
RNN, word by word
3,976 steps
the fee passes along each token
Transformer, all at once
One attention step
any word sees any other word
Detail may fade
an early rule is easy to lose
Clause 40 answered
the fee is linked correctly
- 1The fee rule goes into the RNN at token 12.
- 2It has to travel 3,976 steps, and the detail can fade on the way.
- 3The same rule goes into one attention layer.
- 4Clause 40 looks straight at the fee rule and answers.
Training has a third snag. The signal that says the model was wrong has to travel back through every step, and over long stretches it fades. In 2012, Pascanu, Mikolov and Bengio analysed the vanishing and exploding gradient problems (the learning signal either fades to almost nothing or blows up), which Bengio and colleagues had detailed in 1994.
Put the policy in numbers. Say it is about 4,000 tokens long (a token is a short piece of text, often part of a word). The fee rule sits at token 12 and clause 40 sits at token 3,988. An RNN must pass the fee along 3,976 steps, while an attention layer links the two in one step. Here it is in plain Python. The numbers are fixed, so it shows the arithmetic, not a real model:
# Imagine a 15-page policy of about 4,000 tokens (a made-up size). Clause 1 sets the fee, clause 40 uses it.
# How many steps must the fee rule travel to reach clause 40?
FEE_AT = 12
CLAUSE_40_AT = 3988
rnn_steps = CLAUSE_40_AT - FEE_AT # in the simplest RNN, one token at a time
attention_steps = 1 # one attention layer links any two positions
print(f"Tokens between the two clauses: {CLAUSE_40_AT - FEE_AT}")
print(f"RNN steps to carry the fee rule: {rnn_steps}")
print(f"Attention steps to link them: {attention_steps}")
for gap in (10, 500, 3990):
print(f"Gap {gap:>5}: RNN {gap:>5} steps, attention {attention_steps} step")Output
Tokens between the two clauses: 3976 RNN steps to carry the fee rule: 3976 Attention steps to link them: 1 Gap 10: RNN 10 steps, attention 1 step Gap 500: RNN 500 steps, attention 1 step Gap 3990: RNN 3990 steps, attention 1 step
The numbers are made up, but the shape is real: the gap in steps is the problem attention removes. A production model has many layers and far more going on, so keep the example to the idea, not the exact count.
How do transformers fix this, and what do they cost?
Transformers drop the loop. Each layer computes attention for all positions at once, so the words of a passage are handled together and any two words are linked in one step. The 2017 paper's abstract says the model is based solely on attention and drops recurrence and convolutions entirely.
- RNN
One word after another
Each step waits for the last, and long links need many steps.
- Transformer
All words together
Attention links any two words in one step, and training runs in parallel.
- The cost
Attention grows fast
Every word is compared with every other, so long texts need much more work.
Training in order or all at once
Training text
many passages to learn from
RNN, in order
Word 1, then 2, then 3
each step waits for the last
Transformer, together
All words at once
matrix maths the GPU does well
Training takes longer
its steps can't run side by side
Training ends sooner
up to ten times faster, per Google
- 1The RNN reads each passage one word at a time.
- 2Each step has to wait for the one before, so training is slow.
- 3The transformer hands all the words of a passage to the GPU together.
- 4The GPU works on them in parallel, so training finishes sooner.
The idea of attention came first. In 2014, Bahdanau and colleagues suspected that squeezing a whole sentence into one fixed-size list of numbers was a bottleneck, so they let the model search the source sentence for the parts it needed. Later models such as BERT, a well-known language model, are built on the transformer design.
They replaced RNNs for two reasons: they train faster on modern chips, and they link distant words more directly. The price is a cost that grows with the length of the text. Generating an answer still produces one token at a time, so the parallel gain mostly helps training.
Tip
Say the trade-off before the interviewer asks. Transformers win on parallel training and direct links, and they pay for it on long inputs.
What does the interviewer want to hear?
A strong answer covers
- RNNs and LSTMs read one step at a time, so training cannot run in parallel.
- Long-distance links need many steps, and the learning signal can vanish.
- Attention lets each word look at every other word in one step.
- Transformers train in parallel on GPUs, so training finishes sooner.
- The trade-off: attention cost grows fast with length, and the look-back is limited.
- An honest framing: a design change with costs and limits.
Common traps
Trap"Transformers are just a bigger LSTM."
BetterThey are a different design. No recurrence, and attention does the linking.
Trap"Transformers have no memory limit, so they never forget."
BetterThey can only look back over a limited amount of text, its context window, and attention cost grows with length.
Trap"LSTMs are useless on long text."
BetterLSTMs hold on to more than plain RNNs, but they still pass through every step in order.
Can you spot the wrong line?
Spot the wrong line
A teammate's slide for the interview says this. Which line is wrong?
Quick check
A fraud team scores an endless stream of card swipes on a small device, one reading at a time, with a few milliseconds per reading. Which is the strongest reason to consider a recurrent model?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Learn it in depth
Last updated on 26 November 2026
Building an AI feature on long documents or live data streams?
I design and build AI products and agents, including the interface and the system behind it. Book a short call and tell me what your documents or data look like.