Self-Attention Mechanism
Updated 2026-07-30
Summary
Generates queries, keys, and values from the same sequence and aggregates representations using position-wise compatibility; masks and other constraints determine which positions are visible.
Definition
Self-attention relates different positions of one sequence to construct contextual representations. In Transformer scaled dot-product attention, Q, K, and V are projections of the same sequence representation. Each query assigns weights to accessible keys and aggregates the corresponding values. Causal self-attention masks future positions and cannot access the entire future context.
Introduction
How to use
Information weighting metaphor. When reading or analyzing complex situations, do not exert equal effort. Dynamically compute the relevance between current information and the 'global context', focusing attention on key clues.
Mechanism
Scaled dot-product self-attention computes softmax(QKᵀ/√dk + mask)V: dot products measure compatibility, scaling controls magnitude, masks constrain visibility, and softmax supplies row-wise weights. Multiple heads use different projections and combine their outputs. This enables information aggregation without guaranteeing semantic understanding or correct pronoun resolution.
Practice
In progress 0/1Practice this model in one real situation:
Cases
- Real research example: Vaswani et al.’s Attention Is All You Need uses encoder self-attention and causally masked decoder self-attention for machine translation, alongside encoder–decoder attention and other components. Reported system performance cannot be attributed to one attention head alone.
Common pitfalls
- Self-attention differs from cross-attention that takes keys and values from another sequence, and its weights are not direct explanations or proof of understanding. The number of position pairs in standard dense attention grows quadratically with sequence length; this should not be generalized unconditionally to sparse variants. Order also requires a positional mechanism.
Sources
Source support: Explicit
- en.wikipedia.orghttps://en.wikipedia.org/wiki/Attention_Is_All_You_Needverified
- arxiv.orghttps://arxiv.org/html/1706.03762v7verified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS