01
One state, three roles
A token needs a way to compare with its neighbors—and something to receive from them.
Start with a row of numbers
Read the phrase grid load rises. The word “rises” is more useful when connected to what rises. In a model, that connection has to become a numerical operation. Attention lets one token state combine information from other token states.
If you have seen an embedding, start there: a vector is an ordered list of coordinates. Put one vector on each row of a matrix . In a deeper layer, these rows are already contextual states produced by earlier computation. They need not remain the original embedding-table entries.
A recurrent model carries state along a sequence. Here we will instead calculate a set of weights from one row to the available rows, then form a mixture. We are tracing a forward calculation; the stored model parameters stay fixed.
TOY ASSUMPTION · CL-004
Our labels are grid, load, and rises, with invented states , , and . They were chosen for arithmetic, not learned from text. Neither coordinate is a measured electrical quantity or a verified semantic feature. The example makes no claim about forecasting or document understanding.
Compare with keys; carry values
For each row, create three projections. A query compares with keys. A value is the vector that will enter the mixture. These are roles played by numeric states, not three kinds of token.
A projection is matrix multiplication by a parameter matrix. We use row vectors throughout. For our toy, choose these fixed matrices:
For “rises,” multiply by : the first output is ; the second is . So its key is . The same row has query and value .
| Token / row | Input X | Query Q | Key K | Value V |
|---|---|---|---|---|
| gridrow 0 | [1, 0] | [1, 0] | [1, 1] | [1, 0] |
| loadrow 1 | [0, 1] | [0, 1] | [0, 1] | [0, 2] |
| risesrow 2 | [1, 1] | [1, 1] | [1, 2] | [1, 2] |
Synthetic coordinates. Read across a token row: the same input passes through three fixed matrices. The columns of each vector are coordinates, not probabilities. No position encoding is included in this toy.
The matching key and value coordinates for “rises” are a coincidence of these constants. Keys and values need not have the same width. In a trained model, learning changes the projection parameters; a new input changes the projected states even when those parameters are fixed.
S1 · §§3.2.2–3.2.3 CL-002, CL-003, CL-018
Read the shapes before the numbers
Let be the number of query rows, the number of key/value rows, the query/key width, and the value width. The transpose symbol swaps a matrix’s rows and columns.
The first multiplication gives one comparison for every query/key pair. The second uses one weight per value row. Query and key widths must match; key and value row counts must match. may differ from . In our self-attention example, and both widths happen to be 2.
We have candidates and comparisons. Next we need to turn a row of scores into a controlled mixture.
Derived shape contract · CL-003, from S1 equation (1).