Uploaded November 2026 | Updated November 2026, 1 day ago
My Latest Udemy Courses for 2027:
Google Antigravity: kgptalkie.com/antigravity
Claude Code: kgptalkie.com/claude-code
OpenAI Codex: kgptalkie.com/openai-codex
Decision AI LLM Fine-Tuning: kgptalkie.com/decision-ai-llm-fine-tuning
---------------
LLM Interview 012: Explain query, key and value in self-attention.
Keys and values get cached. The query never does. In an LLM Interview you get exactly this question: "Explain query, key and value in self-attention." Most candidates say "the query is what you search for, the key is what you match, the value is what comes back, like a database". It sounds right, and it gets rejected: that is an analogy, not a mechanism.
- Where they come from: every token has one vector (say 512 numbers). The model has three learned matrices, W_Q, W_K and W_V. Multiply that one vector by all three and you get a query, a key and a value. In the original Transformer's 8 heads, each is 64 numbers. One token, three roles
- The score: take the dot product of the query of "it" with the key of every token. A better match gives a bigger score. Softmax turns the scores into weights, say animal 0.8, street 0.1, everything else 0.1
- The output: the new vector for "it" is a weighted mix of the values: 0.8 times the value of animal, plus the rest. The key is only for finding, the value is what gets passed on
- Why three separate ones: with one shared matrix for query and key, the score would be the same both ways ("it" looks at "animal" exactly as much as "animal" looks at "it"). Separate matrices allow a one-way relation. The value is separate too, because what a token is found by and what it hands over can differ
- Not a database: a database returns one exact match, attention returns a soft blend of all values. And all three matrices are learned in training
- Follow-up, why not cache the query: every new token reads the keys and values of all earlier tokens, so they are reused again and again. The query is needed once, only for the new token. Caching it buys nothing
One-line answer: one vector, three learned matrices; query · key gives the score, softmax gives the weights, a weighted mix of values is the output; query and key are separate so a relation can be one-way; only keys and values are cached.
Next LLM Interview episode: why divide by the square root of d_k? Comment and tell me, which example do you use to explain query, key and value? Follow for the full LLM Interview series.
#LLMInterviewQuestions #LLMInterview #QueryKeyValue #GenAI #KGPTalkie
My Latest Udemy Courses for 2027:
Google Antigravity: kgptalkie.com/antigravity
Claude Code: kgptalkie.com/claude-code
OpenAI Codex: kgptalkie.com/openai-codex
Decision AI LLM Fine-Tuning: kgptalkie.com/decision-ai-llm-fine-tuning
---------------
LLM Interview 012: Explain query, key and value in self-attention.
Keys and values get cached. The query never does. In an LLM Interview you get exactly this question: "Explain query, key and value in self-attention." Most candidates say "the query is what you search for, the key is what you match, the value is what comes back, like a database". It sounds right, and it gets rejected: that is an analogy, not a mechanism.
- Where they come from: every token has one vector (say 512 numbers). The model has three learned matrices, W_Q, W_K and W_V. Multiply that one vector by all three and you get a query, a key and a value. In the original Transformer's 8 heads, each is 64 numbers. One token, three roles
- The score: take the dot product of the query of "it" with the key of every token. A better match gives a bigger score. Softmax turns the scores into weights, say animal 0.8, street 0.1, everything else 0.1
- The output: the new vector for "it" is a weighted mix of the values: 0.8 times the value of animal, plus the rest. The key is only for finding, the value is what gets passed on
- Why three separate ones: with one shared matrix for query and key, the score would be the same both ways ("it" looks at "animal" exactly as much as "animal" looks at "it"). Separate matrices allow a one-way relation. The value is separate too, because what a token is found by and what it hands over can differ
- Not a database: a database returns one exact match, attention returns a soft blend of all values. And all three matrices are learned in training
- Follow-up, why not cache the query: every new token reads the keys and values of all earlier tokens, so they are reused again and again. The query is needed once, only for the new token. Caching it buys nothing
One-line answer: one vector, three learned matrices; query · key gives the score, softmax gives the weights, a weighted mix of values is the output; query and key are separate so a relation can be one-way; only keys and values are cached.
Next LLM Interview episode: why divide by the square root of d_k? Comment and tell me, which example do you use to explain query, key and value? Follow for the full LLM Interview series.
#LLMInterviewQuestions #LLMInterview #QueryKeyValue #GenAI #KGPTalkie










