Pro
Pro lesson

Attention

How a real language model, GPT-2, works out which earlier words matter to each word.

This one’s part of How Models Learn Pro — every lesson, every interactive, and new ones as they land. About 14 minutes.

Already Pro? Sign in and you’ll go straight in.

Inside “Attention”

What you’ll learn

  1. What does “it” mean?
  2. The whole pattern as a grid
  3. Queries and keys
  4. From scores to shares
  5. Mixing in the values
  6. Many heads at once

Key terms

Attention
A mechanism that lets each token weigh how relevant other tokens are to it, then mix in their information.
Token
A chunk of text, often a word or part of a word, that a language model reads and writes.
GPT-2
A language model released by OpenAI in 2019. The small version has 124 million parameters, 12 layers and 12 attention heads per layer, and was trained on WebText, about 40 GB of web pages.
Query
In attention, a vector describing what a token is looking for.
Key
In attention, a vector describing what a token offers, matched against queries.
Value
In attention, the information a token passes on to the tokens that attend to it.
Dot product
Multiply two vectors number by number and add up the results. Large when they point the same way.
Softmax
Turns a list of scores into positive weights that add up to 1; a score one point higher than another gets about 2.7 times its weight, so large gaps in score become very large gaps in weight.
Causal attention
Attention in which each token can only look at itself and earlier tokens. Used by models that write text one token at a time.
Attention head
One independent set of queries, keys and values. GPT-2 small has 12 per layer, 144 in all.
Induction head
A kind of attention head that finds an earlier copy of the current token and looks at the token that followed it.
Attention sink
A token, often the first one, where heads put attention when nothing else is useful.
Transformer
A neural network design built from stacked layers of attention and other parts. It powers most modern language models.

Sources