Attention / Core
verifiedQuery, Key, Value
Attention borrows its vocabulary from databases. Each position emits a query — what am I looking for — and every position also offers a key, advertising what it has. Queries and keys are matched to decide where to look; the value is what actually gets read once the match is made. Splitting the three lets a position advertise something different from what it delivers.
Three learned projections of the same input: Q = XW sub Q , K = XW sub K , V = XW sub V . Keys and queries must share a dimension because they are dotted together; values need not, and their dimension sets the output width. Separating K from V is what lets the model be found for one reason and read for another, which a single shared projection cannot express.
For input X ∈ ℝ super n×d sub model , W sub Q , W sub K ∈ ℝ super d sub model ×d sub k and W sub V ∈ ℝ super d sub model ×d sub v . In self-attention all three project the same X; in cross-attention Q comes from one sequence and K, V from another. The parameter cost is d sub model ·(2d sub k + d sub v ) per head.
8 queries against 8 keys; a brighter cell means more of that query's attention went to that key. Nothing is masked: every position can read every other, itself included.
Query rows against key columns, with weight shown by cell brightness. Drag the sequence length to see how many pairings the projection has to score.
Reviewed by opendroid · 2026-08-04
- arXiv:1706.03762 — Attention Is All You Need