esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

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.

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

  1. 1The fee rule goes into the RNN at token 12.
  2. 2It has to travel 3,976 steps, and the detail can fade on the way.
  3. 3The same rule goes into one attention layer.
  4. 4Clause 40 looks straight at the fee rule and answers.
Clause 1 sets the fee and clause 40 uses it. An RNN passes the fee along token by token, so the link is long and weak. An attention layer lets clause 40 look straight at the fee in one step.

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:

Python
# 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

  1. 1The RNN reads each passage one word at a time.
  2. 2Each step has to wait for the one before, so training is slow.
  3. 3The transformer hands all the words of a passage to the GPU together.
  4. 4The GPU works on them in parallel, so training finishes sooner.
The same passage can be trained two ways. The RNN takes its steps in order, while the transformer hands all the words to the GPU together. Google reported in 2017 that this could speed training up by up to an order of magnitude (about ten times).

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

1 / 6

What will they ask next?

  1. Q043What is self-attention?11 min
  2. Q044What are queries, keys and values?11 min
  3. Q046What is multi-head attention?10 min
  4. Q047What is positional encoding, and why is it needed?11 min
  5. Q049Encoder-only vs decoder-only vs encoder-decoder?11 min

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.