techtree / Attention
Attention scores
Dot each query with every key, then softmax into weights.
Transcript
Take the query of one token: draws. Line it up against the key of every token in the sentence.
Dot the query with each key: one, four, two. A bigger number means a better match.
Then divide each by the square root of the number of entries. Here that is two. This keeps the scores from getting too large.
Softmax turns the scores into weights. They are all positive, and they add up to one.
Draws pays the most attention to plotter.
Every token does the same, with its own query. Each row holds one token's weights, and every row adds up to one.
A query, held up against every key, decides where a token looks.
Needs
- Queries, keys, and values video
Three matrices turn each token vector into a query, a key, and a value. - Dot product video
Multiply matching entries and add them up; one number that measures agreement. - Exp and softmax video
Turn any list of scores into positive weights that add up to one.
Everything this builds on (10 topics, in order)
Leads to
- Self-attention video
Each token's output is a weighted average of the value vectors.