Log inStart free
LESSON 9.01 · 6 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Queries, keys, values and attention scores

Watch one token's query score every key, then mix the values.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 2 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 9.01 · ATTENTION BAYQUERY SAT · 4 NUMBERS PER TOKEN
01
Stage 1 of 6 · Queries
W_Q turns each token vector into a query. The query says what the token looks for.
Explain it simply

Each row on the left is one word as 4 numbers. Multiply a row by the ochre grid, W Q, and you get its query. A query is like a search phrase: it says what this word looks for. These grids hold seeded random numbers; a trained model learns its own.

Six token rows of 4 cells. Each row times W Q gives a query row. The query of “sat” is marked.

token vectorsweight matricesscores and output
thecatsatonamatW_Qxqqueries: q = x · W_Qq “sat” = [1.92, 0.39, −1.37, −0.83]thecatsatonamatW_Qxqqueries: q = x · W_Qq “sat” = [1.92, 0.39, −1.37, −0.83]
Toy: 6 tokens, width 4, seeded weights (not trained)
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
qi=xi WQ\sy{q}{data}{q_i} = \sy{x}{data}{x_i}\,\sy{wq}{param}{W_Q}
qsat=xsatWQ=[1.92,0.39,−1.37,−0.83]q_{\text{sat}} = x_{\text{sat}} W_Q = [1.92, 0.39, -1.37, -0.83]

The query is the token vector times the query weights.

Common mix-ups

MYTHA token's query always matches its own key best.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01Change the scaling from ÷ √4 to none. Does the weight of “sat” on “the” go up or down?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 2 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.