The Transformer, Explained
Theme
Palette
Download
Caption (tap to copy)
📖 Deep dive (full written explanation)
This post answers the 'so what.' Knowing that a Transformer stacks attention blocks is only useful once you understand why that design beat everything before it so decisively that a single 2017 paper effectively reset the field. The answer is not hype; it is two concrete structural properties that previous architectures could not offer.
The through-line is that the Transformer solved parallelism and long-range dependency at the same time, and those two wins unlocked scaling. Scaling, in turn, unlocked the entire modern era — from large language models to protein structure prediction. This post traces that chain of cause and effect.
The timeline frames the takeover as an evolution, not a bolt from the blue. Attention first appeared in 2014 bolted onto recurrent seq2seq models for translation, where it helped but was bottlenecked by the underlying RNN. The 2017 Transformer made the radical move of keeping attention and discarding recurrence entirely. By 2018, BERT and GPT showed that pretraining these models at scale produced general-purpose language understanding and generation.
From 2020 onward the architecture spilled out of NLP into vision, audio, and the sciences. The lesson of the timeline is that the key breakthrough was subtractive: the real leap was realizing that attention alone, without the recurrent scaffolding, was not just sufficient but better.
Parallelism is the first decisive advantage, and it is about hardware as much as math. An RNN must process token t before token t+1, so a thousand-token sequence forces a thousand sequential steps, during which a massively parallel GPU sits mostly idle waiting on the chain. A Transformer instead computes all positions simultaneously as large matrix multiplications, which is exactly the operation GPUs are built to saturate.
The consequence is that the same training data flows through a Transformer far faster than through an RNN of comparable size. That speed is not a luxury — it is the precondition for training models with billions of parameters on trillions of tokens. Without parallelism, the scale that defines modern models would simply be infeasible.
Long-range context is the second decisive advantage. In an RNN, information from the first token must survive being overwritten at every subsequent step to influence a token five hundred positions later, and in practice it rarely does — this is the vanishing-information problem that plagued recurrent models. Attention removes the chain entirely: every token has a direct, single-hop connection to every other token.
That directness is decisive for any task with real long-range structure — long documents, source code where a function defined early is called much later, multi-turn conversations. The model can attend straight from a late token back to an early one with no decay. For these problems the difference between lossy recurrence and direct attention is the difference between coherent and incoherent output.
This bar chart visualizes the structural advantage in terms of path length — how many steps information must travel for the first token to influence the last. In an RNN that path is O(n): it scales linearly with sequence length, which is why long-range signals decay. A CNN shortens it to O(log n) by stacking layers with widening receptive fields, better but still growing with length.
Attention collapses the path to O(1): a single hop regardless of distance. Shorter paths mean both better gradient flow during training and less information loss at inference. The chart makes the abstract point tangible — the Transformer's edge on long-range dependencies is not a tuning detail but a property baked into its connectivity.
A subtler reason for the takeover is that attention is a general-purpose mixer with almost no built-in assumptions. A CNN assumes a grid with local structure; an RNN assumes a one-dimensional chain. Self-attention assumes neither — it simply learns, from data, which elements should influence which, whatever their arrangement.
That generality is why the identical core architecture handles text, image patches, audio frames, and amino-acid sequences with little more than a change in how the input is encoded into vectors. One mechanism spans modalities that used to each demand bespoke architectures. This is also the deeper reason the Transformer escaped NLP: it was never really a language model design, but a general sequence-and-set modeling tool.
Scaling laws are what turned the Transformer's efficiency into a strategy. Because these models train in parallel and keep improving as you add data and parameters, their performance follows smooth, predictable curves: more compute, more data, and more parameters reliably lower the loss in a way you can extrapolate before you spend the money.
That predictability changed model-building from a gamble into an engineering investment. If you know that a 10x larger model trained on 10x more data will reach a measurably lower loss, scaling becomes a budgeting decision rather than a research bet. This is precisely why the field raced to build ever-larger models — the Transformer made the payoff of scale forecastable.
This snippet contrasts the two execution models directly. The RNN version is an explicit Python loop over sequence positions, each step depending on the previous hidden state — inherently serial, and the reason the GPU stays underused. The Transformer version computes a full n-by-n score matrix in one matrix multiplication and applies softmax across all positions at once.
The code makes the parallelism concrete: there is no loop over time in the attention computation, just batched linear algebra. That structural difference is the entire performance story in miniature. When people say Transformers are 'GPU-friendly,' this is what they mean — the core operation is exactly the dense matmul the hardware is optimized for.
This mindmap captures the breadth of the takeover. The same Transformer core anchors language models like GPT and BERT and machine translation; vision systems like ViT that treat image patches as tokens; audio models like Whisper that process speech frames; and scientific tools like AlphaFold that model protein sequences.
The point is not to memorize the examples but to internalize the pattern: in field after field, a domain-specific architecture was replaced by a Transformer with a modality-appropriate input encoding. That convergence is one of the most striking developments in modern machine learning, and it follows directly from attention being a general mixer rather than a language-specific trick.
Honesty about the costs keeps the post credible and sets up the mistakes post later in the day. The headline cost is quadratic complexity: because every token is compared with every other, compute and memory grow with the square of sequence length, so long inputs get expensive fast. Transformers are also notoriously data-hungry, since they lack the strong inductive biases that let CNNs learn from less. And because attention is order-blind, they need explicit positional encodings just to know token order.
The broader point is that the Transformer's power is not free. Each of these costs has spawned an entire line of research — efficient attention variants, data-efficient training, better positional schemes — and ignoring them in practice leads directly to the failures the final post catalogs.
This recap gathers the argument into five points: parallel training unlocked the scale that defines modern models; direct attention paths beat the lossy recurrence of RNNs on long-range structure; attention generalizes across modalities because it makes few structural assumptions; smooth scaling laws made investing in size a rational engineering decision; and all of this comes at the cost of quadratic attention and a heavy appetite for data.
Together these explain not just that the Transformer won, but why — and they warn that its advantages come with real bills. With the motivation established, the next post opens the hood on the mechanism doing all this work: attention itself.
The teaser sets up the mechanics post. With the case for why the Transformer matters in hand, the next step is to see exactly how attention works — how each token produces a query, a key, and a value, and how those turn into the weighted mixing that does all the heavy lifting. That is where the architecture stops being a black box.