Before you can read the parent note Computational complexity of attention, you need to own every symbol it throws at you. We build them one at a time. Nothing is used before it is drawn.
A token is one small chunk of text the model reads: usually a word or piece of a word. If you feed the model the sentence "cats love naps", that is 3 tokens.
Look at the figure: each coloured box is one token. Lining them up in a row is literally what "a sequence of length n" means. Everything expensive in attention grows as this row gets longer.
A computer cannot multiply the word "cats". So each token is turned into a list of numbers — like coordinates that place the word somewhere in a space of meaning. Similar words land near each other.
Look at the figure: each token box now has a column of d numbers stacked under it. A vector is just that column — a list of numbers with a fixed length. We write "a vector lives in Rd", which is fancy for "it is a list of d real (ordinary) numbers".
This is the single most important mechanic in the whole topic, so we slow right down.
To multiply a matrix of shape (a×b) by a matrix of shape (b×c):
The inner numbers must match (both are b). They "cancel", and the result has shape (a×c).
Each cell of the result is made by lining up one row (length b) with one column (length b), multiplying the pairs, and adding them up — that is b multiplications per cell.
There are a×c cells.
Look at the figure: one highlighted result cell is fed by one row (violet) and one column (orange), each of length b. Count the arrows — that's b multiplications for one cell. Repeat for all a⋅c cells and you have the total.
Each token asks a question, offers a label, and carries content. So each token-vector is turned into three new vectors:
Here dk is the width of one query/key/value vector — often equal to d, or to d/h when we split into heads (Section 8). Full mechanics live in 4.1.1-Self-attention-mechanism.
To score how well token i's query matches token j's key, we multiply the query row by the key row. Doing this for all pairs at once needs the keys turned on their side — that is the transpose.
Now the score matrix:
S=QKT,(n×dk)×(dk×n)=(n×n).
Using the cost formula with a=n,b=dk,c=n:
cost=n⋅dk⋅n=n2dk.
Look at the figure: the output S is a full square of side n. Cell (i,j) is the score "how much should token i attend to token j". A square of side n has n2 cells — this is the birthplace of the quadratic cost the whole topic warns about.
The scores are first divided by dk (square root of the key width). Why? Bigger vectors give bigger dot-product scores just because there are more terms to add; dividing by dk shrinks them back so softmax does not become razor-sharp. It answers the question "how do I keep scores at a sane scale regardless of dk?"
Finally each token's output is a weighted blend of all value vectors:
Output=AV,(n×n)×(n×dk)=(n×dk),cost=n2dk.
Look at the figure: the orange linear line (∝n) and the magenta quadratic curve (∝n2) start close, but the quadratic soon rockets away. That crossover is exactly why long sequences hurt, and why 4.3.2-Sparse-attention-patterns and 4.5.1-Memory-optimization-techniques exist. Position information itself must also scale with n — see 5.2.3-Positional-encoding-scaling.