Multi-Head Self-Attention Workspace
Select any query token or attention head below to inspect the mathematical dot product routing that allows tokens to contextualize their meaning.
๐ Query, Key & Value Intuition
Think of self-attention like an information retrieval database: the Query ($Q$) represents what a token is looking for; the Key ($K$) represents what each token offers or advertises; and the Value ($V$) is the actual substantive semantic content delivered when a match occurs.
๐ Why Multi-Head Attention?
A single attention head can only focus on one relationship at a time. Multiple heads allow the model to simultaneously track syntactic dependencies (e.g. subject-verb agreement), entity coreferences (pronoun resolution), and positional relationships across different semantic sub-spaces.
โ๏ธ Why Scale by $\sqrt{d_k}$?
For large vector dimensions $d_k$, the dot product $Q \cdot K^T$ grows large in magnitude. Large inputs push softmax into regions with vanishingly small gradients. Dividing by $\sqrt{d_k}$ preserves unit variance and maintains healthy gradient flow during training.