Transformers
What Is Attention?
Attention decides which earlier words to mix into the word being read now.
01 / Pronoun
Which word is "it"?
The model scores earlier words and mixes their meaning into "it".
How the mix answers the pronoun
A person might pick "dog" because hungry animals chase. The model compares "it" with earlier words and keeps a weighted blend of their meanings.
The 0.71 and 0.19 numbers are illustrative. A trained model would emit its own scores.
02 / Query, Key, Value
Score, then mix.
Query is the look-up, Key is the label, and Value is the payload that gets mixed in.
Why the scores get divided by √dₖ
- Each word makes three vectors: Query, Key, and Value.
- The score is how well this Query matches each Key.
- Divide by √dₖ so the scores stay in a range softmax can use. Large raw dots push softmax toward 0 and 1 (Vaswani et al., §3.2.1).
- Softmax turns the scaled scores into weights that add to 1.
- Those weights mix the Values. The result is the new vector for this word.
03 / Masks
Who can look where.
Encoder words all see each other, and decoder words skip any word that has not been written yet.
Why a decoder hides the future
- Rows are the word that is looking. Columns are the word being looked at.
- An encoder may let every token attend to every token, including later ones in the same pass.
- A decoder that writes one token at a time uses a causal mask. Future tokens do not exist yet, so those cells stay muted.