Attention in transformers: queries, keys and context
3Blue1Brown explains how attention updates token representations using surrounding words.
What you will learn
Grant Sanderson follows query, key and value vectors through softmax, masking and multiple attention heads. The adjective-and-noun example illustrates possible behavior, rather than explaining every learned head.
Who it suits
Before starting, use the preceding transformer lesson to distinguish tokens from their vector embeddings. It explains how representations carry meaning and how context changes them. This makes the attention diagrams easier to follow.
Published in April 2024, this foundations lesson uses GPT-3 examples. This guide relies on the creator’s written adaptation.
Try it: a CurioFuse exercise
An original editorial exercise with a checkable outcome.
CurioFuse context exercise: one word, two readings
Write two invented sentences: “She sat on the bank beside the river” and “She visited the bank to discuss a loan.” Underline the words you use to interpret “bank” in each. Then cover the surrounding words and note what information disappears.
Your explanation is useful when it identifies different contextual clues without assigning invented attention scores. Use the lesson to refine your vocabulary for those relationships. This is our language exercise, not a visualization of a specific model's attention heads or a claim about their measured behavior.
Sources(3)
- Attention — official videoChecked:
- Attention — written lessonChecked:
- Transformers — preceding lessonChecked:


