3

Query, key, value

Every word makes a question, a name tag and a message by multiplying with three matrices.

Hover or tap a word to follow its row. Tap empty space to reset.

blue frame: learned weights (training changes them)green frame: numbers worked out for this sentence
1The idea, with readable numbers
Module 3, step 1: The idea, with readable numbers

Every word gets three things: a question (what am I looking for?), a name tag (what do I have?) and a message (what do I pass on?). These numbers are made up by hand.

question = query, name tag = key, message = value. Match = dot product q·k.

2How one row is computed
Module 3, step 2: How one row is computed

Cat's question comes from cat's row of X times a table W_Q. Each slot: multiply pairs, add them up.

qcat = xcat · WQ (1×3 · 3×3 = 1×3). That is a matrix multiplication.

3Three tables, three jobs
Module 3, step 3: Three tables, three jobs

Do that for every word with three different tables, and you get all questions, name tags and messages.

Q = X·WQ, K = X·WK, V = X·WV. Each 4 × 3. The W tables are learned.

Each word now has a question, a name tag and a message: Q, K, V, each 4 × 3. Next, cat uses its question to look back at the others.