What are Query, Key, and Value in attention?medium
Every token is projected into three learned vectors: Query (what this token is looking for), Key (what this token offers for matching), and Value (the actual information it carries). Attention scores come from Q·K similarity, and the result is used to decide how much of each token's Value to pull in.
A useful analogy is library search: your search query is matched against book indexes (keys), and strong matches return the book content (values). For the word "it" in "The cat sat because it was tired," the Query for "it" may look for the entity being described; the Key of "cat" matches strongly, so the model pulls the Value of "cat" to understand the sentence. Formally, attention scores are softmax(Q·Kᵀ / √d_k), then multiplied by V — high Q-K similarity means the model attends heavily to that token's Value. This is the mechanism by which context relationships, like pronoun resolution or subject-object binding, actually get captured inside a transformer layer.