Unit 2 · Architecture
Lesson 05 · Available to read
The Transformer Revolution: Attention Is All You Need
The 2017 architecture that replaced recurrent networks: attention, residual streams and the stacked transformer block.
In 2017 a team at Google published a paper with a bold title: "Attention Is All You Need." The architecture it introduced, the transformer, now underlies essentially every large language model. This lesson explains what it replaced, the core idea of attention, and how the full architecture fits together. Lesson 6 then does the maths of attention in detail.
Before transformers: reading one word at a time
Earlier language models were mostly recurrent neural networks (RNNs), including LSTMs. They read text left to right, one token at a time, squeezing everything seen so far into a single fixed-size hidden state.
That design had two big problems:
- A memory bottleneck. By the end of a long paragraph, details from the beginning had to survive being overwritten again and again in one vector. Long-range connections were hard to learn.
- No parallelism. Token 100 can't be processed until token 99 is done. Training couldn't make full use of GPUs, which excel at doing many things at once.
The core idea: attention
The transformer's answer: let every token look directly at every other token and decide which ones are relevant to it.
Consider: "The animal didn't cross the street because it was too tired." To understand "it", the model should pull information from "animal" (not "street"). Change "tired" to "wide" and the right referent becomes "street". Attention computes, for each token, a set of weights over the other tokens and builds a new representation as a weighted blend of them.
(In a decoder-only LLM, tokens can only look backwards — Lesson 6. So "it" can only see the words before it; the final resolution happens a few positions later, when the token "tired" or "wide" looks back at both "it" and the candidate nouns.)
Because every pair of tokens is compared at once, the whole sequence can be processed in parallel during training, and distant words are only one step apart instead of hundreds.
The architecture, bottom to top
A GPT-style (decoder-only) LLM processes text like this:
- Tokenize the text and look up embeddings (Lessons 2–3); add position information (Lesson 7).
- Pass the vectors through N identical transformer blocks (dozens to over a hundred).
- Apply a final normalization, then the unembedding layer, which produces a logit for every vocabulary token.
- Softmax turns the logits into next-token probabilities.
Each transformer block contains two sub-layers:
- Multi-head self-attention — tokens exchange information with each other.
- Feed-forward network (MLP) — each token's vector is processed on its own: expanded to a wider hidden size (often about 4×), passed through a nonlinearity, and projected back.
A useful division of labour: attention moves information between positions; the MLP transforms information within a position. Interpretability research suggests that much of a model's factual knowledge is stored in the MLP weights, which also hold roughly two-thirds of the parameters.
The residual stream
Each sub-layer doesn't replace its input — it adds its output to it:
x ← x + Attention(Norm(x))
x ← x + MLP(Norm(x))
These residual (skip) connections mean there is a running vector for each token — the residual stream — that flows up through the whole network. Every block reads from it and writes small updates back into it. This has two big benefits:
- Gradients can flow straight down the skip paths during backpropagation, so very deep stacks remain trainable.
- Each layer only needs to learn a refinement, not a whole new representation.
Layer normalization rescales each vector to a standard size before each sub-layer, keeping numbers in a stable range. Most modern LLMs normalize before each sub-layer ("pre-norm"), as in the formulas above.
Scale
The blocks are identical in shape but each has its own weights. GPT-3, for example, stacked 96 blocks with a residual-stream width of 12,288. Making the stack deeper and wider is the main way models grow (Lesson 8).
Three family members
The 2017 paper used an encoder–decoder design for translation: an encoder reads the source sentence with full attention, and a decoder generates the translation. Descendants split into three families:
- Encoder-only (e.g. BERT) — sees the whole text at once; great for classification and search embeddings, not for generating text.
- Encoder–decoder (e.g. T5) — good for transforming one text into another.
- Decoder-only (GPT-style models, and most chat LLMs today) — each token can only attend to earlier tokens, which makes it a natural next-token predictor (Lesson 6 explains the causal mask).
Why it won
Parallel training on GPUs, direct connections between distant tokens, and a simple, repeatable block that keeps improving as you scale it up. Those three properties are why one architecture went from machine translation to powering chatbots, code assistants and multimodal models.
The takeaway
The transformer replaced step-by-step recurrence with attention, letting every token look at every other token in parallel; an LLM is a deep stack of identical blocks — attention to move information between tokens, an MLP to process it — all reading from and writing to a shared residual stream.
Practice
0 of 7 attempted
- 1Recall
Name two limitations of recurrent neural networks that the transformer addressed.
Saved in this browser
- 2Explain in your own words
In "The trophy didn't fit in the suitcase because it was too big", what does "it" refer to? What if "big" became "small"? In a decoder-only model, at which token can the model finally resolve the reference, and how does attention help?
Saved in this browser
- 3Recall
What are the two sub-layers inside every transformer block, and what is the job of each?
Saved in this browser
- 4Explain in your own words
What is the residual stream, and why do residual connections make deep networks easier to train?
Saved in this browser
- 5Multiple choice
Which transformer family do most chat LLMs belong to?
- 6Calculate
A model's residual stream has width d = 4,096 and its MLP expands to 4d. Ignoring biases, how many weights are in one block's MLP (one matrix up, one matrix down)?
Saved in this browser
- 7Apply
Draw (on paper) or write out the path a single token takes from text to next-token probability in a decoder-only transformer. Include at least six stages.
Saved in this browser