Query, Key, Value › Query, Key, Value

Michael BrenndoerferUpdated June 4, 20252 min read
Language AI HandbookAll chapters
Part 13 of 67Self-Attention
Chapter 91Query, Key, Value › Query, Key, Value
Reading section 1 of 11 · Query, Key, Value · 2 minSection 1 of 11 · 2 min

Book contents

Section 1 of 11 · 2 min read

Query, Key, Value › Query, Key, ValueOne section · Sections in this chapter1 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

In the previous chapter, we implemented self-attention using raw embeddings: each token's embedding served directly as the basis for computing similarities and aggregating context. This approach works, but it has a fundamental limitation. When a token computes dot products with other tokens using its own embedding, it's asking: "Which tokens are similar to me?" But similarity isn't the same as relevance. A pronoun like "it" isn't similar to "cat" in embedding space, yet "cat" is highly relevant for understanding what "it" refers to.

The solution is to give tokens different representations for different roles. When a token is looking for context (querying), it should express what information it needs. When a token is being looked at (acting as a key), it should advertise what information it offers. And when a token contributes to another token's representation (providing a value), it should supply the actual content to be aggregated. This separation of concerns is the Query, Key, Value (QKV) framework.