Skip to content

Quick Recap of Attention Is All You Need

Published:

I have typed “ChatGPT” a thousand times and never stopped to ask what the T stands for. It stands for Transformer, the engine inside ChatGPT, Claude, Gemini and almost every model I use. These are my notes from Transformers explained in 12 minutes by Kind of Burgundy. The video and all the diagrams below are theirs.

The whole idea in one paragraph

A Transformer turns each token into a list of numbers (an embedding). Then, layer after layer, it does two things. Attention lets every token look at every other token and pull in the context it needs. The MLP lets each token add facts the model memorised during training. After the last layer, the model predicts the next token, appends it, and runs again. Because every token is processed at the same time instead of in a line, it runs well on GPUs, which is why it could be scaled up into GPT.

What the model actually does

It reads the text so far, predicts the next token, appends it, and predicts again. Every answer I have ever got was written one token at a time.

A token is the unit the model reads and writes: a short word, or a piece of a longer one. An English word is a little over one token on average. So when a model says it can read 200,000 tokens at once, that is the unit.

To predict the next token well, the model has to understand everything before it. The whole game is how good that prediction is.

The problem before 2017: RNNs

Before the Transformer, the standard design was the recurrent neural network (RNN). It read the way we do, one token after another. After each token it updated a small running summary and moved on. That caused two problems.

An RNN reading "I arrived at the bank after crossing the river" one token at a time, still holding "bank" when it reaches "river" The RNN has to carry “bank” all the way to “river”. Frame from Kind of Burgundy, 2:16.

  1. It forgot. In “I arrived at the bank after crossing the river”, you only know “bank” means riverbank at the last word. The RNN had to carry that link through every token in between, like a message whispered down a row of people. In a long text it got lost.
  2. It was slow. Token 10 had to wait for token 9. GPUs are built to do thousands of things at once, and reading in a line wasted them.

The 2017 paper from Google, Attention Is All You Need, asked a different question: what if every token looked at every other token at the same time?

Step 1: tokens become numbers

A Transformer never sees text, only numbers. Each token becomes a list of numbers called a vector (512 of them in the original paper). That vector is the token’s embedding. Think of it as coordinates in a space of meaning, where tokens with similar meanings sit close together: “cat” near “dog”, “Paris” near “France”.

The catch: at the start, a token gets the same embedding in every sentence.

The token "bank" gets the identical vector in "She put money in the bank" and "We sat on the river bank" Same word, same starting numbers, whatever the sentence means. Frame from Kind of Burgundy, 3:32.

So the Transformer’s real job is to update each embedding, moving it in that space until it matches what the token means in this sentence. The mechanism that does the moving is attention.

One more detail. Since tokens are no longer read in order, the model would not know that “dog bites man” differs from “man bites dog”. So each embedding also gets a positional encoding added: a small signal that says where in the sentence the token sits.

Step 2: attention, in three steps

The video uses an example Google itself used:

The animal didn’t cross the street because it was too tired.

You know instantly that “it” is the animal. Change “tired” to “wide” and “it” is the street. The model works it out like this:

  1. Query. Every token produces a query vector, a question. The query from “it” asks: who am I talking about?
  2. Key. Every token also produces a key vector, a label describing itself. The key from “animal” says: I’m a living thing, I can get tired. The key from “street” says: I’m a place.
  3. Score. The query from “it” is compared with every key. The better the match, the higher the score. Softmax then turns the scores into percentages that add up to 100%.

Attention pattern for "it": 75% on "animal", 17% on "street", the rest near zero Each token has a query (Q) and a key (K). “it” puts 75% of its attention on “animal”. Frame from Kind of Burgundy, 5:39.

Those percentages are the attention pattern. Then “it” absorbs information from the other tokens in those proportions. What each token hands over is a third vector, its value. So “it” takes 75% of what “animal” offers, 17% of “street”, and a little of the rest. Its embedding moves, and in meaning space it now sits near “animal”. Swap “tired” for “wide” and the scores flip towards “street”.

How to remember Q, K, V: the query is what I’m looking for, the key is what I am, and the value is what I’ll give you if you pick me.

The part that surprised me: nobody wrote those queries, keys or values. They come from numbers (parameters) the model learned by predicting the next token billions of times and being nudged a little each time it was wrong. That nudging is all training is.

Heads and layers

Step 3: the MLP, where knowledge lives

Despite the paper’s title, attention isn’t all a Transformer needs. Attention only moves information between tokens. It can’t add anything that isn’t already in the text.

Take “The Eiffel Tower is in”. “Paris” appears nowhere in that sentence, so attention has nothing to copy. The answer has to come from the model’s own memory, and that memory lives in a second block.

Five tokens pass up through a shared attention layer, then each goes through its own MLP block One layer: attention mixes the tokens, then each token goes through the MLP on its own. Frame from Kind of Burgundy, 7:58.

After every round of attention, each embedding passes on its own through a multilayer perceptron (MLP), a small neural network. No token talks to another here.

Researchers think this is where much of the model’s knowledge is stored. In GPT-3, about two-thirds of the parameters sit in these MLP blocks.

So one layer is: attention gathers context, then the MLP adds what the model knows. Repeat for every layer, then predict the next token.

Why it won: parallelism

It did not win by being smarter. It won by being parallel. No token waits for the one before it, so the whole sentence is processed at once, which is exactly what GPUs are built for. The paper’s biggest model trained in three and a half days on eight NVIDIA GPUs and set a new record for English-to-German translation.

The real consequence came later: a design that runs in parallel is a design you can make bigger.

From translation to GPT: encoder and decoder

The 2017 paper was about translation, so the original Transformer had two halves:

Both halves are made of the same pieces: attention, then an MLP, stacked in layers.

OpenAI kept only the decoder, the half that writes, and trained it on thousands of books to do one thing: predict the next token. They published it in 2018 and called it a Generative Pre-trained Transformer, or GPT:

The 2017 Transformer had about 200 million parameters; GPT-3 had 175 billion. Same idea, roughly 800 times bigger.

The price: the context window

If every token looks at every other token, the work grows with the square of the length. Double the text and you get four times the work. That is why every model has a context window. The Transformer’s biggest strength is also its bill.

Cheat sheet

Term What it means
Token The unit the model reads and writes; a word or part of one
Embedding A token as a list of numbers, a position in “meaning space”
Positional encoding A signal added to each embedding to say where the token sits
Query What a token is looking for
Key What a token is, as a label others match against
Value What a token hands over when others attend to it
Softmax Turns raw scores into percentages that add up to 100%
Attention pattern How much each token listens to every other token
Attention head One attention pattern; models run several in parallel
MLP Per-token network that adds stored knowledge
Layer Attention + MLP; models stack dozens
Encoder / decoder The reading half and the writing half; GPT keeps only the decoder
Context window Max tokens at once; cost grows with the square of the length

The famous title started as a joke: Llion Jones borrowed it from the Beatles’ “All You Need Is Love”.

Credits and sources

I have not yet checked each figure in the video against the paper.

GitHub Goes SHA-256