Artificial intelligence · lesson 3 of 4
Attention, softmax and transformer structure
Scaled dot-product attention forms weights softmax(QKᵀ/sqrt(dk)) and uses them to combine value vectors. Dimensions and masks are part of the definition.
Learn the ideas
Prerequisites: Linear algebra, probability and neural layers.
Attention
Scaled dot-product attention forms weights softmax(QKᵀ/sqrt(dk)) and uses them to combine value vectors. Dimensions and masks are part of the definition.
Softmax
Softmax converts a finite score vector to nonnegative weights summing to one. A common additive shift leaves the result unchanged.
Position
Pure self-attention without position information is permutation-equivariant. Position representations and masks supply relevant ordering structure.
Interpretation
Attention weights are internal computational quantities. They should not automatically be treated as complete causal explanations of a model output.
Worked examples
Two attention scores are both zero. Find either softmax weight.
exp(0)/(exp(0)+exp(0))=1/2.
0.5
Attention weights are 0.25 and 0.75, and scalar values are 2 and 6. Find the weighted value.
0.25×2+0.75×6=5.
5
Check your understanding
8 questionsDecimals or fractions are accepted for numeric answers. Proofs and written responses use sample answers and require human marking. This is practice, not a protected examination.
Further reading and review references
These are reference links, not copied exercises, institutional endorsement or proof of independent review.