AI & ML

Attention

Part of Deep Learning, level 4. About 9 hours of study across the topics below.

Create free account

Query, Key, ValueSimilarity ScoresScaling and SoftmaxWeighted AggregationSelf-AttentionMulti-Head AttentionMaskingCross-AttentionEfficient Attention

1Mechanism

  1. Query, Key, ValueThree roles, one retrieval: what the query asks, what keys offer, what values deliver. 1–2 h
  2. Similarity ScoresHow well does each key match? Query-key alignment, scored. 1–2 h
  3. Scaling and SoftmaxScores into weights: why divide by root-d, and the sum-to-one guarantee. 1–2 h
  4. Weighted AggregationThe mixture is the message: values averaged by weights into one output. 1–2 h

2Sequence Attention

  1. Self-AttentionA sequence attending to itself: every token contextualized by weighted others. 1–2 h
  2. Multi-Head AttentionParallel views, one output: heads attend differently, then concat and project. 1–2 h
  3. MaskingInformation control: causal and padding masks decide what may attend to what. 1–2 h
  4. Cross-AttentionQueries from one sequence attending to keys and values from another: how decoders read encoders and text reads images. 1–2 h
  5. Efficient AttentionAttention's quadratic cost and the fixes: IO-aware kernels, sparse and sliding windows, and linear approximations. 1–2 h