Natural Language Processing · free preview
Self-Attention
Contextual embeddings from weighted sums of neighbors, queries, keys and values, scaled dot-product scores, and multiple heads.
1. Self-Attention
Self-Attention
2. Queries, keys, values, and heads
Queries, keys, values, and heads
3. Attention weights in NumPy
Attention weights in NumPy
4. Softmaxing attention scores
A token attends to three prior tokens with raw scores , , . Compute the attention weight for the first token after the softmax, round to three decimals.
5. Why divide by the root of the dimension
A query-key dot product is with head dimension . Compute the scaled score and round to three decimals.
6. Queries, keys, and values
Match each projection to its role in one attention head.
7. Masking with minus infinity
In the masked attention matrix for a causal language model, future positions receive the value before the softmax rather than 0. Why?
8. Head width in multi-head attention
A transformer has model dimension and attention heads, with the usual choice so all heads share the budget. What is ? Answer with the number.
Practice this interactively
Free account · instant grading · spaced review that schedules itself.
Start this course for free