Q,K,VQ, K, V

Query, key, value

Three learned versions of each token's vector. The query is what the token is looking for, the key is what it offers to others, and the value is what it passes on. W^Q is read "W Q", the matrix that makes queries.

One vector would have to serve as a search term, a search label and the content itself, and those roles would get in each other's way. So the model learns three separate weight matrices and makes three versions of each token:

  • qi=xiWQ\mathbf{q}_i = \mathbf{x}_i W^Q: what am I looking for?
  • ki=xiWK\mathbf{k}_i = \mathbf{x}_i W^K: what do I offer?
  • vi=xiWV\mathbf{v}_i = \mathbf{x}_i W^V: what do I contribute if chosen?

Attention compares every query with every key to get scores, then mixes the values using those scores. The raised QQ, KK, VV are labels, not powers. A fourth matrix, WOW^O, maps the mixed result back to the model's width.

Where the course uses it

Related terms