Attention doesn't know where anything is
Self-attention decides how much one token should attend to another using a single number — a dot product. That number has no idea how far apart the two tokens actually sit.
Inside every attention layer, each token is turned into two vectors: a query — the question a token is silently asking ("what am I looking for?") — and a key — the advertisement a token holds up ("here's what I've got"). How well they match is just a dot product: multiply matching numbers together, add them up.
Try it — push "mat" further from "cat"
Each cell is still the same two content vectors. Only the distance between them changes.
q_i · k_j.What m and n actually mean
Before the notation gets any thicker: number a sentence's tokens starting from zero — that's each token's position, just its slot in the line. Recall score(i,j) = q_i · k_j: token i is the query, asking; token j is the key, being looked at. Position-embedding papers rename these two positions with single letters, and it's worth memorising which is which:
If "cat" (position 1) is asking about "mat" (position 5), then m = 1 and n = 5, and the gap between them is n − m = 4. Click any two words below — the first click sets m, the second sets n.
i. It has nothing to do with sentence position — it names which slice of a single vector's numbers is being discussed, not which word. m and n answer "which word." i answers "which piece of that word's vector."The 2017 fix — stamp a position onto the meaning
Every token starts life as an embedding — a vector encoding its meaning, computed purely from the word itself, with no idea where it landed. The original transformer's fix: compute a second vector that depends only on position — built from sine and cosine waves at different frequencies — and add it straight onto the embedding.