How can one token use information from another?
Read: “The animal didn't cross the street because it was tired.” To interpret “it”, information from earlier words matters. Treating every position as equally useful would be wasteful.
Attention is a learned mechanism that lets each position assign different weights to other allowed positions and combine their information.
Attention asks: which earlier words are useful here?
The sentence The animal didn't cross the street because it was tired is shown with stronger conceptual emphasis on the pronoun it and the words animal and tired.
Query, Key and Value — without the mystery
Q, K and V in plain English
From matching scores to attention weights
Compare Query with Keys
A dot product gives larger scores to stronger matches in the learned space.
Scale the scores
Divide by √dₖ, where dₖ is the Key-vector dimension, to keep large dot products from making softmax excessively sharp.
Normalize with softmax
Convert the scores into non-negative weights that sum to 1 across the allowed positions.
Mix the Values
Multiply each Value vector by its attention weight and add the results.
A tiny weighted-value calculation
Suppose one query produces attention weights 0.731 and 0.269 over two positions. Their Value vectors are [1, 0] and [0, 2].
0.731 × [1, 0] = [0.731, 0]
0.269 × [0, 2] = [0, 0.538]
Output = [0.731, 0.538]
The result is not a label. It is a new representation containing a weighted mixture of information from the two Value vectors.
The weighted result is a new representation for a token, not the final generated word. The surrounding Transformer layers process that representation further; the architecture comparison below explains which positions are allowed to exchange information.
One attention operation is not the whole Transformer
Inside a Transformer block
Multiple heads are useful, but a head is not guaranteed to have one fixed human-readable job such as “grammar head”.
Three common Transformer families
Architecture family and typical use
Why the next lesson matters
The Transformer can now produce scores for possible next tokens. How does the system choose which token to actually generate?
Text Generation & Decoding →Summary / Key Takeaways
- Attention lets each token position weight information from other allowed positions.
- Query supports looking for a match, Key supports matching, and Value carries the information to mix.
- Scaled dot-product attention turns Q–K scores into weights and uses them to combine V.
- Multi-head attention, feed-forward layers, residual paths, and normalization form a Transformer block.
- Decoder-only Transformers use causal masking and are a natural fit for next-token generation.
- The Transformer produces useful contextual representations; the next lesson explains how scores become actual generated tokens.