Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M0090

Self-Attention Mechanism

Self-Attention Mechanism
TechnicalHigh supportArtificial Intelligence
Included
account_tree

Updated 2026-07-30

Loading revision record…

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.

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/1

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

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

  • link
    en.wikipedia.orghttps://en.wikipedia.org/wiki/Attention_Is_All_You_NeedEN · Explicit
    verified
  • link
    arxiv.orghttps://arxiv.org/html/1706.03762v7EN
    verified
account_treeGenealogyexpand_more

RELATED MODELS