Skip to main content

Review — Queries, keys and values

Back to the lesson · Learning path plan

What to remember

  • A self-attention head projects each state into a query Q, key K and value V using learned matrices.
  • For one position, the query is compared with keys from accessible positions. The score contributes to the weight assigned to each position.
  • The output combines the values using those weights. Keys contribute to comparison, and values provide the content being aggregated.

Recall from memory

With Q, K and the mask fixed, what can changing V affect within one head?

Show the answer

Changing V can change the weighted sum. The weights depend on the scores computed from Q and K and the positions allowed by the mask.

Visual card — From scores to output

At one position, which projections feed the score calculation and which feed the weighted sum? Place Q, K, and V in slots A, B, and C.

Show the card answer

A = Q and B = K. The scaled dot product of the current query and each accessible key gives one score. Softmax gives the weights over the accessible positions. C = V. The output is the sum of the values weighted by those weights.

Language · Français · English