Scaled Dot-Product Attention › Summary
Language AI HandbookAll chapters Scaled Dot-Product Attention › SummaryOne section · Sections in this chapter14 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Scaled dot-product attention maps QKV inputs into context-enriched representations through four sequential operations:
- Dot product (): measures pairwise similarity between all queries and all keys, producing an score matrix with cost
- Scaling (): normalizes scores to have unit variance, preventing softmax saturation and enabling stable gradient flow throughout training
- Softmax: converts scores row-wise into probability distributions over positions, producing attention weights with
- Weighted sum (): aggregates value vectors according to attention weights, producing a -dimensional context-aware representation for each position
The causal mask extends this mechanism to autoregressive generation by zeroing out attention to future positions before softmax. Combined with the padding mask for batched computation, the masking mechanism handles all common production use cases. Both types of masking work by adding to score matrix entries before softmax, which causes those positions to receive exactly zero weight in the output.
The quadratic complexity in both computation and memory is the central scalability challenge. Efficient attention variants address this bottleneck, which we'll examine in the Attention Complexity chapter. Before that, the next chapter covers multi-head attention, which runs multiple instances of scaled dot-product attention in parallel to allow the model to attend to different aspects of the input simultaneously. Multi-head attention is the direct generalization of everything we've covered here: it applies scaled dot-product attention not once but times, with different learned projections for each head, and concatenates the results. Understanding scaled dot-product attention fully, as we've done in this chapter, is the necessary foundation for understanding why multi-head attention works so well in practice.