RNN vs Transformer: What Changed, What It Costs and What the Tests Show

RNN vs transformer: what is the difference?
RNN vs transformer comes down to how they read: an RNN (recurrent neural network) reads one token, a word or part of a word, at a time and carries one running summary forward, while a transformer layer lets each token draw on the other tokens in one step (a model that writes text lets each draw on earlier ones only).
In “The keys to the cabinet are on the table”, an RNN must carry “keys” past “cabinet” to get “are” right, and in tests LSTMs, improved RNNs, mostly do. A transformer trains all positions at once but scores every pair of tokens. At equal estimated cost, the 2017 transformer beat an RNN by 3.8 BLEU, a translation score (our derivation).
The transformer architecture is the 2017 design this article compares with the RNN, and what a transformer layer does has its own article.
Both designs turn each token into a vector, a list of numbers the model learns, and stack layers, stages that rework those vectors.
How each design reads the same sentence
The verb “are” is plural because its subject, “keys”, is. The nearest noun, “cabinet”, is singular, so a model that copies the number of the last noun gets the verb wrong.
An RNN reads left to right. After each token it computes a new state, one vector, from the previous state and the token. The plural of “keys” must survive in that state past “to”, “the” and “cabinet”: a path of 4 steps (our count).
A transformer layer has no chain. In its attention step, each token takes a mix of information from all the other tokens (in a model that writes text, only from the earlier ones), each share computed from learned numbers. So “are” can draw on “keys” in a single step.
That is what the design allows, not a measured share. How the shares are computed belongs to attention. Because a layer reads all tokens at once, the model is given each token’s position (in the 2017 paper, added to its vector): positional encoding.
What changed in 2017
Vaswani and colleagues introduced the transformer in Attention Is All You Need. Their first argument was the RNN’s chain: its “inherently sequential nature precludes parallelization within training examples.” Without it, a GPU (graphics processor) can train on all positions of a sentence at once.
The second argument was the path: the shorter it is between two positions, “the easier it is to learn long-range dependencies.” Easier, not impossible before: RNNs learn the link too, as tests below show. One part stayed sequential: a model that writes text produces one token at a time.
The price: a score for every pair
Attention scores every pair of tokens, so one layer fills a table with as many rows and columns as the text has tokens. Its work grows with the square of the length, a recurrent layer’s only in step with it.
For translated sentences, the paper says, attention was cheaper, as a sentence usually had fewer tokens than each vector had numbers. With more tokens than that, attention costs more per layer (our reading of the paper’s Table 1); the attention variants and their limits explains that cost and its fixes.
What the first results showed
On an English–German news translation test, the larger transformer scored 28.4 BLEU (how much of a machine translation matches human translations), more than 2 points above the best earlier systems, combined models included. Training took 3.5 days on 8 P100 GPUs, with less estimated compute than the best earlier combined models (Table 2 below).
If you only wanted to know how an RNN and a transformer differ, you can stop here.
The numbers behind the comparison
The paper’s Table 1 sums up the trade-off: n is the number of tokens, d the length of each token’s vector, O(…) grows in proportion to, O(1) does not grow.
| Layer type | Work per layer | Steps that must run one after another | Longest path between two tokens |
|---|---|---|---|
| Self-attention | O(n²·d) | O(1) | O(1) |
| Recurrent | O(n·d²) | O(n) | O(n) |
Table 2 gives the translation results on newstest2014, a news test set. GNMT is a 2016 translation system built from LSTMs (an improved RNN, see below) with attention. The cost is the authors’ estimate in floating-point operations (FLOPs), training time × GPUs × assumed speed per GPU, not a measurement.
| System | English–German BLEU | English–French BLEU | Estimated cost, English–German (FLOPs) |
|---|---|---|---|
| GNMT + RL, recurrent, single model | 24.6 | 39.92 | 2.3 × 10¹⁹ |
| GNMT + RL, 8 models combined | 26.30 | 41.16 | 1.8 × 10²⁰ |
| Transformer, base | 27.3 | 38.1 | 3.3 × 10¹⁸ |
| Transformer, big | 28.4 | 41.8 (arXiv v5+) or 41.0 (NeurIPS 2017) | 2.3 × 10¹⁹ |
RL = refined with reinforcement learning after normal training.
At the same estimated cost as the recurrent single model, the big transformer scored 3.8 points higher on English–German (our derivation). Against the best earlier combined models (1.8 × 10²⁰ in the table, and 7.7 × 10¹⁹ for one not shown) the big transformer’s estimate is lower.
The step in between: attention on top of an RNN
In 2014 Bahdanau and colleagues studied an RNN encoder–decoder: one RNN, the encoder, squeezes the source sentence into one fixed-length vector; a second, the decoder, writes the translation from it. They called that vector “a bottleneck” and let the decoder take a weighted sum of all encoder states for each word.
On English–French news-test-2014, their RNN with attention scored 26.75 BLEU against 17.82 without it. The transformer kept the attention and dropped the recurrence (layout: encoder-decoder architecture).
Most RNNs tested below are LSTMs (long short-term memory networks). Hochreiter and Schmidhuber built them in 1997 because in a plain RNN the error signal that training sends back through the steps tends to blow up or vanish: the vanishing gradient. Learned gates control what enters and leaves the state; recurrent neural networks covers how.
The agreement tests, in both directions
Linzen and colleagues made the shared sentence a test in 2016: the model sees “The keys to the cabinet” and guesses whether the next verb is singular or plural. A noun of the other number in between, like “cabinet”, is an attractor.
| Study | Setup | Result |
|---|---|---|
| Linzen et al. 2016 | LSTM with a state of 50 numbers, trained to predict the verb’s number on Wikipedia sentences | 0.83 % errors overall, 17.6 % with four attractors; no considerable loss up to 15 words apart with no noun between |
| Tran et al. 2018 | LSTM vs transformer on Linzen’s data; small models (2 to 4 layers) trained from scratch | LSTM “slightly but consistently” better; the gap grows with distance and attractors |
| Tang et al. 2018 | English–German translation; subject and verb more than 10 words apart | transformer 97.1 % correct; LSTM 95.1 %, deeper bidirectional LSTM 96.3 %; the deeper LSTM did equally well or better from a distance of 13 words |
| Goldberg 2019, preprint | BERT, a transformer pre-trained on large amounts of text, seeing both sides of the verb | 0.96 to 0.97 correct with 1 to 4 attractors; not directly comparable, the author says |
Tang et al. tested the 2017 path-length argument directly and found no clear transformer advantage at long distances. The other studies were not built to test it. None supports “recurrence cannot”: the three that tested LSTMs (Linzen, Tran, Tang) found them accurate overall.
No controlled modern-scale comparison was found, so these results may not hold at today’s sizes.
Where recurrent models still matter
The Mamba paper (Gu and Dao, 2023) says attention does not compress the context: a model generating text stores data for every earlier token, the KV cache, which makes it effective and costly. A recurrent model keeps one state of fixed size: cheap, but only as good as its compression.
Mamba, one of the state-space models, is a newer recurrent design. Its authors report two separate measurements. On quality, in pretraining and in tests without task-specific training (300 billion training tokens of the Pile, a text collection), a Mamba with 3 billion parameters (learned numbers) matched transformers twice its size.
On speed, measured on other model sizes, Mamba generated 4 to 5 times as much text per second as transformers of similar size, on an A100 GPU. They tested only models below 7 billion parameters.
Hochreiter’s group built xLSTM (2024) with a variant, mLSTM, that is “fully parallelizable”. The classic LSTM and xLSTM’s other variant, sLSTM, link hidden states from one time step to the next (“memory mixing”), which “enforce[s] sequential processing”. So the first 2017 argument applies to some recurrent designs, not all: mLSTM’s recurrence is rewritten in a parallel form for training.
When it breaks: reading one paper’s result as a law. The same agreement task gave the LSTM the lead in Tran et al.’s small models trained from scratch, and a pre-trained BERT without fine-tuning scores 0.96 to 0.97 in a setup that is not directly comparable, so a “cannot” claim needs its model size, data and training next to it.
Cheat sheet
The article on one page: open it full size, save it or share it.

AI-assisted content, human-reviewed. Images AI-generated. Editorial Standards · Our Editors