Definition
Self-Attention
Self-attention updates each token’s representation using other positions in the same sequence. It compares a query at the current position with keys at permitted positions, then uses the resulting weights to combine their values. Masks determine which positions are visible. A causal decoder excludes future positions.
Combine two values using attention weights
Take two visible positions with scaled scores ln(2) and 0. Their exponentials are 2 and 1, so softmax assigns weights 2/3 and 1/3. If the value vectors are simplified to the scalars 6 and 0, their weighted sum is 4. A causal mask removes any position to the right of the current token from that calculation.
Scaled dot-product attention in the Transformer paper
Intelligence at Scale by Shashank Agarwal

Explained in
Chapter 3: Attention Is All You Need FreeThe paper behind every major AI model today. Google invented it. Then watched someone else ship it.
Related terms