Main Point
Attention uses query–key compatibility to weight value information from allowed source positions. A causal mask enforces the information boundary before normalization and mixing.
Key Points
- Learned parameter matrices produce input-dependent queries, keys and values.
- Queries and keys participate in matching; values carry information into the mixture.
- Softmax normalizes scores across the allowed source positions.
- The output is a weighted combination of value vectors.
- Causal prediction excludes future positions even when a teacher holds the complete example.
- Attention-position weights and output-vocabulary selection describe different operations.
1. Fix the available input
For this classroom diagram, the supplied units are `The`, `package`, `arrived`, `after`, `it`. These word-like units are not a measured production tokenizer result. At the final input unit `it`, a causal computation can use the known prefix, including that current input position, while preparing a next-token prediction.
Keep the full teacher record separate. A later continuation such as `was delayed` cannot supply information to this earlier causal prediction. Architecture determines the allowed connections; another type of model can use a different mask.
2. Separate the numerical roles
A position's representation is transformed with learned parameters to produce Q, K and V. The matrix parameters can stay fixed while these computed vectors change with the input.
| Object | Role in the operation |
|---|---|
| Query at the current position | Participates in compatibility with candidate source keys |
| Key at a source position | Participates in matching the query |
| Value at that source position | Supplies vector information to the weighted combination |
These are numerical roles. Q is a computed vector, and K is a computed vector rather than a manually assigned database keyword. The input representations and the learned transformations determine their values.
3. Follow scores into a mixture
Vaswani and colleagues' 2017 Transformer paper describes scaled dot-product attention. Its dot products compare queries and keys; division by a dimension-dependent factor controls the score scale before softmax. The next lesson supplies already-scaled scores for a small calculation.
For the defined allowed set, softmax exponentiates each score and divides by the sum of those exponentials. Finite allowed scores yield positive shares summing to 1. Multiply each corresponding value vector by its share and add matching coordinates. Several source positions can contribute to the output vector.
The combined vector continues through the model. It is distinct from the later projection and selection over vocabulary tokens. A high attention weight on a position labelled `package` does not itself instruct the system to print that word.
4. Enforce the mask before normalization
Self-attention draws Q, K and V from representations of the same sequence. Other arrangements can draw information from a separately represented input. The original Transformer uses different encoder and decoder connections; our classroom example isolates a causal prefix.
If the teacher's record contains `was delayed` after `it`, the mask excludes those later positions from this earlier calculation. Recompute the shares over the remaining allowed scores. Removing a contribution while leaving a total below 1 would no longer implement the defined normalized mixture.
The mask is part of the operation. Asking a model to ignore text while permitting the relevant information path is a different control arrangement.
5. Inspect the result at the right scope
One attention weight captures part of a computation. Other positions, heads, layers and transformations can affect the final output. Evaluate the actual response and task alongside the mechanism. The technical name alone establishes neither human consciousness nor a complete faithful explanation of an answer.
6. Closing
You can now trace a current-position query through compatibility, allowed-position shares and value mixing. You can also find a causal information leak in a proposed diagram. The numerical lesson will make the normalization and weighted-vector arithmetic inspectable, including what changes when a position is masked.
7. Learning Checks
Attempt each question before opening the explanation. Keep the separate worksheet blank during your attempt.
M14-L05-Q01
A causal model has only the supplied prefix “The package arrived after it.” A teacher’s complete record also contains the later words “was delayed.” What information does attention combine? May those future words contribute to the earlier calculation? Would a large weight on 1 position completely explain the final response?
Your explanation: ____________________
Show explanation after your attempt
Attention combines value vectors using weights derived from query–key compatibility over allowed source positions. Apply the causal mask before normalization so the later continuation cannot contribute to this earlier calculation. Normalize the allowed scores and form their weighted value mixture. A large attention weight is part of a wider computation, so a final-response explanation also needs the remaining model and task evidence.
M14-L05-P01
Use the supplied prefix “The report was revised after.” A proposed causal-attention diagram gives a large weight to a later editor position from the teacher’s completed record. Explain how to repair the allowed connections and weights, and what would be passed forward.
Your repaired diagram and reasoning: ____________________
Show explanation after your attempt
Exclude the later editor position from this earlier causal calculation. Retain the defined known prefix positions, including the current input position. Recompute normalization over allowed scores so their shares sum to 1, then combine the corresponding value vectors. The result continues through model computation; it is not itself a vocabulary-token selection or proof of factual truth.
Sources
- Vaswani, Ashish; Shazeer, Noam; Parmar, Niki; Uszkoreit, Jakob; Jones, Llion; Gomez, Aidan N.; Kaiser, Łukasz; Polosukhin, Illia. *Attention Is All You Need*. Original preprint 12 June 2017; v7, 2 August 2023. Primary paper, sections 3.2–3.2.3 and 3.4; version history. Retrieved 30 October 2026. Used for the historical computation and mask. No original translation benchmark or classroom attention-map measurement is adopted.