Attention & Self-Attention
In One Sentence
A mechanism that lets each token dynamically look up and blend information from every other relevant token in the context window.
ELI5 (Intuition)
When you read 'The trophy didn't fit in the suitcase because it was too big,' your brain automatically shines a spotlight back onto 'trophy' to know what 'it' means. Attention is that learned spotlight.
ELI18 (Technical)
Each token projects to Query (\(Q\)), Key (\(K\)), and Value (\(V\)) vectors and computes \[\operatorname{Attention}(Q, K, V) = \operatorname{softmax}\!\left(\frac{QK^\top}{\sqrt{d_k}} + M\right) V,\] where causal mask \(M\) blocks future tokens during autoregressive generation. Multi-head attention runs several parallel spotlights.
In Practice
Self-attention's \(O(T^2)\) pairwise cost is why long contexts get expensive—and why engineers rely on FlashAttention, Grouped-Query Attention (GQA), and prompt caching to serve 128k+ token windows fast.