Score
Each query compares with every permitted key by dot product. Larger alignment produces a larger logit.
A transformer scores query-key pairs, scales the logits, masks forbidden positions, and applies softmax. Change each stage and see where probability mass moves.
Open the attention fieldEach query compares with every permitted key by dot product. Larger alignment produces a larger logit.
Division by √d keeps variance controlled. A causal mask sets future logits to negative infinity before softmax.
Softmax creates nonnegative weights summing to one. The output is their weighted combination of value vectors.
Low temperature amplifies logit differences and concentrates probability. High temperature flattens the distribution. It does not create new token relationships; it changes how decisively existing scores are interpreted.
Decoder self-attention cannot read future positions during training or generation. Masking occurs before softmax so forbidden tokens receive exactly zero probability rather than merely a small weight.
Residual streams, value vectors, multiple heads, MLPs, and later layers determine the final behavior. High weight indicates routing in one head, not necessarily causal importance for the output.
Dot-product variance grows with dimension. Scaling keeps logits in a range where softmax gradients are less likely to saturate.
No. Heads use separate projections and can specialize in local, positional, syntactic, or semantic relations, though specialization is not guaranteed.
Lower temperature expands score gaps, concentrating probability into fewer positions and reducing distributional uncertainty.
Vaswani et al. (2017) introduced scaled dot-product multi-head attention. Brown et al. (2020) describes causal transformer language modeling at scale. Jain and Wallace (2019) investigates whether attention weights are explanations. Elhage et al. (2021) develops transformer-circuit interpretations of attention heads.