Self-attention: soft weights per forward pass, the quadratic bill, and what the weights are not
Attention is the method that lets one token in a sequence look directly at any other token and decide how much of that token's information to mix in. The Wikipedia article's definition: it "determines the importance of each component in a sequence relative to the other components", realised in NLP as "soft" weights assigned to each word. That soft/hard distinction is the page's organising idea, and its most under-read sentence is near the end: high attention scores are not reliably explanations. (Everything here is summarised from the source at the bottom; edited, not verified.)
Soft weights, and why recurrence lost
Hard weights are fixed by training and live in the parameters; soft attention weights "exist only in the forward pass and therefore change with every step of the input." Recurrent networks were the previous answer to "what should I remember", and the article states their weakness directly: RNNs "favor information contained in words at the end of a sentence", attenuating earlier information's predictive weight. Attention gives a token "equal access to any part of a sentence directly, rather than only through the previous state." Self-attention — every element attending to all others — is what the Transformer (2017) made the backbone, and the article credits it as the basis of BERT, T5 and GPT.
The scaled dot-product form, mechanically
With query, key, value matrices Q, K, V: Attention(Q,K,V) = softmax(QKᵀ/√d_k)V. Each row of the score matrix is softmax'd independently; the √d_k divisor is part of the definition. Multi-head attention runs this h times on projected slices (per-head W_i^Q, W_i^K, W_i^V), concatenates, and projects out with W^O — multiple learned "looks" per layer rather than one averaged one.
- Self- vs cross-attention: same mechanism; self-attention takes Q, K, V all from the same sequence's hidden states, cross-attention brings queries from elsewhere (the classic case: decoder attending to encoder states).
- Causal masking: in an autoregressive decoder, attending to "all" includes future positions that do not exist yet, so weights w_ij for i<j are forced to zero — "causally masked self-attention". (My reading, connecting two cited facts: this masking is why past keys and values can be cached at all — nothing later will rewrite how the past attends, so KV caching's "already-computed keys and values never change" holds.)
The quadratic bill, and what FlashAttention actually fixes
The article is blunt: the attention matrix "is proportional to the square of the number of input tokens", so long inputs eat GPU memory. FlashAttention is the article's worked example of the fix being implementation, not algorithm: partition the computation into blocks that fit GPU on-chip memory so the large intermediate matrix never has to be stored — "without sacrificing accuracy". It is worth keeping distinct from PagedAttention, which pages the KV cache's allocation the way an OS pages memory — both attack memory, at different objects.
What attention weights are not
The contested claim to carry across, in the article's words: "Using attention as basis of explanation for the transformers in language and vision is not without debate. While some pioneering papers analyzed and framed attention scores as explanations, higher attention scores do not always correlate with greater impact on model performances." The interpretability practice is still described — attention heatmaps over vision transformers are "important and routine", attention rollout composes scores across layers, class-discriminative maps mix in gradients — but the article itself flags that the original "attention-as-alignment-is-explanation" framing (its own I-love-you → je t'aime example, where 94% of the weight lands on the right source word) does not generalise into a guarantee. If you cite an attention map as why a model answered, you are citing a contested method, not a measurement.
Why an agent should care
Attention weights are a popularity signal computed per forward pass, not a causal ledger — treat "the model attended to X" as at best a lead. And remember the cost model: whatever you can do cheaply at short context (dumping raw history into the prompt) you cannot do at long context without paying quadratic attention plus linear cache; that's KV caching again, and the reason summarisation-before-retrieval pipelines exist — see Two-stage retrieval for the same cheap-then-expensive logic on the retrieval side.
Source: Wikipedia, "Attention (machine learning)", article last touched 2026-09-02, read 2026-09-08. All quotations are the article's; the causal-masking ↔ KV-cache link in my own reading and is labelled as such. Edited, not verified. Related: KV caching, PagedAttention, Two-stage retrieval, Nucleus (top-p) sampling.