ContentsThe library

The Mathematics of Attention

One Weighted Average Is Not Enough

Last timeSoftmax Over Scores

A single attention head produces one mixture per token, and a mixture destroys information. Heads are how the mechanism keeps several answers at once.

Everything so far has described one head: one set of three projections, one

score matrix, one softmax, one weighted sum. That mechanism works. The question

this lesson answers is why no real model uses only one of them.

The limit of a single head

A head produces, for each token, one vector: a weighted average of the values,

with the weights summing to one.

The problem is in the word average. Averaging is not invertible. Given the

result, you cannot recover what went in. If the weights land half on one token

and half on another, what comes out is the midpoint of two value vectors, and

the midpoint of two meanings is generally not a meaning at all.

Take a sentence where one token needs two different things at once:

The researcher who wrote the paper said it was wrong.

For said, a useful representation depends on at least two relationships. Its

subject is researcher, four tokens back and separated by a relative clause.

Its complement is the clause beginning at it. These are different questions

with different answers.

One head must answer both with one set of weights. The options are all bad: put

the weight on the subject and lose the complement, split it and get a blend of

two unrelated vectors, or spread it thin and get mush.

FIG 1One head forced to cover two relationships
Neither relationship is represented cleanly. The output is a blend, and nothing downstream can separate the subject contribution from the complement contribution.

Two heads dissolve the problem. One puts nearly all its weight on the subject,

the other on the complement, and both results survive into the output because

they occupy different coordinates.

The lesson stops here

7 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Why Attention Needs Three Matrices, Not One
  2. 02Where the Square Root of dkd_k Comes Fromopening only
  3. 03Why Softmax and Not Some Other Normalisationopening only
  4. 04One Weighted Average Is Not Enoughyou are here
  5. 05Attention Cannot See Order, So Order Has to Be Addedopening only
  6. 06The Skip Connection Is the Main Roadopening only
  7. 07Why Transformers Normalise Across Features and Not Across the Batchopening only
  8. 08The Half of the Transformer That Does Not Move Informationopening only

Read alongside