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
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.
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.
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.