Plain-language explainer
Query, Key and Value, explained
What do Query, Key and Value actually mean in attention?
Attention is a search. Each token asks a question, its Query. Each token also advertises what it contains, its Key, and carries the content it would hand over, its Value. Matching a Query against every Key produces scores, softmax turns the scores into shares, and the token's new representation is the share-weighted blend of the Values. All three roles are computed from the same token vector through learned weight matrices. Nobody writes them; training finds them.
Do not just read it. Operate the mechanism yourself in a short interactive lesson.
See it work: Query, Key, Value βFree, no code, no signup.
What people get wrong
- Q, K and V are stored properties of words. They are produced fresh, per position and per layer, by learned matrices multiplying the token's vector.
- The model looks words up in a fixed table. Scores are computed from the live context, which is why the same word attends differently in every sentence.
- Attention chooses the answer. It only decides which information flows where. Scoring the next word happens later, at the top of the stack.
Where you see it in real products
- Attention heatmaps in AI visualizations are these Query-Key scores drawn as color.
- The reason 'bank' resolves to river or money per sentence is this per-context matching.
- Long-document question answering works because Queries can fish the one relevant passage out of thousands of Keys.
Related explainers
Part of See How AI Works, a free interactive course, where you learn how modern AI works by operating it, not watching videos.