Narration · Module 22
Q / K / V
0:00 / 0:00
Module 22 · Architecture · 8 min

Q, K, V - the projections.

The matrices that turn embeddings into queries, keys, values.

Reading time8 min Audionarration available Prerequisites12 SourceTrack A · Gemini
§ 1

What this lesson covers.

This module is one of 42 in the curriculum. Below is the canonical interactive lesson — tabs, cards, and diagrams from the source repo, rendered inside the course shell. An audio narration runs alongside it - the sticky player at the top of the page plays the full Module 22 clip.

If you prefer to read first and play with the demos after, the interactive lesson sits below this section. If you'd rather hear it narrated while you scroll, hit play on the sticky audio bar at the top — or just let it autoplay.

Read / reason / test

Three learned roles from one representation

High school · build the intuition

Queries, keys and values are learned transformations, not three independent facts inside a token. A query describes what the current position seeks, a key provides a matching representation, and a value supplies what can be mixed. This analogy helps orient the process, but the operations are matrix multiplications. Changing learned projections changes how the same input participates in attention.

College · work the example

If X has shape 3×4 and each projection has shape 4×2, Q, K and V each have shape 3×2. Q times K-transpose produces 3×3 scores; normalized scores times V produce 3×2 outputs. Check dimensions before numbers. The example uses one head and equal key/value widths for convenience, not as a universal architecture rule.

Explain it back

Describe the process in your own words. Identify the assumption that makes this example work, then explain one conclusion it cannot establish.

Read the primary source or official documentation →

The numerical examples are authored teaching exercises, not measured model benchmarks. This extension adds context to the original lesson.

§ 2

The lesson itself.

Interactive lesson · ported from Gemini track Click tabs to navigate · hover cards for details

QKV Matrix Projection

Before a token can pay attention to other words, it must split its single dense embedding into three distinct mathematical roles: Query (Q), Key (K), and Value (V). It does this by multiplying its embedding vector against three massive learned weight matrices ($W_Q$, $W_K$, $W_V$).

0.412
-1.104
0.893
2.301
Token Embedding Vector (e.g. "king")
WQ Matrix
WK Matrix
WV Matrix
0.12
0.45
-0.9
1.1
Query (Q)
"What I am looking for"
1.80
-0.2
0.31
0.77
Key (K)
"What properties I contain"
-0.6
2.34
0.11
-1.9
Value (V)
"My actual semantic payload"
§ DEMO

Try it: qkv projection.

One token embedding becomes three vectors via three learned matrices. See Q (query), K (key), V (value) computed live for any token.

QKV Projection · interactiveOpen standalone
§ PAPERS

Further reading.

The canonical references for this module. External links open in a new tab.

§ NEXT

What to read next.

Use the pager below to move sequentially through the curriculum, or jump to any module from the course index. Each track has a "Prereq: ↑ foundation" callout so you can backfill anything that wasn't clear.