Interactive widget · free · embeddable
Query, Key, Value: run one attention lookup by hand
The word drinks holds up its Query. Tap the word whose Key you think matches best, then watch the score and the Value flow.
Where do Query, Key and Value come from?
Each word starts as its single embedding (from 1.2). The model multiplies that embedding by three separate grids of numbers to make three views, a Query, a Key, and a Value. Each view is a vector, so the score is just their dot product, the same one from Lesson 1.3.
Those grids are learned in training, nobody writes them by hand. The next lesson builds Query, Key and Value step by step and shows exactly where the numbers come from.
What you will do
- 1One word asks a question. Tap the earlier word whose Key you think answers it.
- 2See the match scored: a dot product between the Query and each Key, the same operation used to compare embeddings.
- 3Watch the winning word's Value flow into the asking word, so it now knows what its subject is.
What it shows
Attention is a search, and this widget lets you run one lookup by hand. Every word starts as one embedding. The model multiplies that embedding by three learned grids of numbers to make three views of the same word: a Query, which asks a question, a Key, which advertises what the word contains, and a Value, which is the content it hands over when it is chosen.
When drinks holds up its Query, every earlier word offers its Key. The score for each pair is a dot product, multiply the matching slots and add them up, exactly the similarity trick from the embeddings lessons. The highest score wins the biggest share, and that word's Value flows into drinks. In the sentence on the stage, cat wins, so drinks now carries the knowledge that a cat is doing the drinking.
The numbers on the bars and the numbers in the expanded view are the same numbers. Nothing hidden happens between them. That is the point of running it by hand: the whole of attention at one position is a few multiplications and an addition.
Why it matters
This is the machinery that disambiguates words by context. In the sentence I left the bank to fish by the river, bank sends a Query, river answers with a Key that scores high, and the Value of river shifts bank toward the water sense. Multi-head attention runs many of these lookups in parallel, and a transformer stacks dozens of layers of them. Once the single lookup is clear, the rest of the architecture is repetition.
Key takeaway
Attention reuses the dot product you already know. A Query against each Key gives scores, and the top score wins the biggest share of Value.
Honest note: The Query and Key numbers here are readable toy values. Real ones are learned in training and have hundreds of dimensions. The lesson that follows this one shows exactly where those grids of numbers come from.
This widget is one stage of a full lesson, with the story around it.
Free, no code, no signup.
Embed this widget
Paste this into any HTML page, course platform, wiki or slide tool that accepts an iframe. It runs with no account, sets no cookies of its own, and links back here.
Attribution is built in. If you write about it, a link to this page is all we ask.
Common questions
- What is the difference between a Key and a Value?
- The Key is what a word advertises so others can decide whether to attend to it. The Value is what the word actually delivers once chosen. Scoring uses Keys; the blend that updates the asking word uses Values. Both come from the same embedding through different learned matrices.
- Is the dot product really all there is to the score?
- For one head at one position, yes: multiply matching slots and add. Real models scale that sum by the square root of the dimension and run softmax over all the scores so they become shares that add to one. The widget shows the raw scores so you can check the arithmetic yourself.
- Can I put this widget in a lecture or a course page?
- Yes. The embed snippet on this page drops the stage into any HTML page or slide tool that accepts an iframe. It runs with no account and links back to the full lesson.
Related explainers
One idea at a time, in your inbox
New lessons and explainers, written the way these pages are. Now and then, not daily, and never a sales sequence.
We email you a confirmation link first. Unsubscribe in one click, any time. Privacy.
Part of See How AI Works, a free interactive course, where you learn how modern AI works by operating it, not watching videos.