Deconstruct the core math that powers modern LLMs (GPT-4, Gemini, Claude). Step through linear Query (Q), Key (K), Value (V) projections, scaled dot products, softmax probability normalizations, multi-head attention decomposition, and causal autoregressive masking.
Move your cursor over any matrix cell on the left to see the exact dot-product, scaling, and softmax computations.
For large dimensions, dot products grow large in magnitude, pushing Softmax into regions with extremely small gradients (≈ 0). Scaling by 1/√d_k preserves unit variance.
Decoder models like GPT prevent tokens from looking into the future by setting upper-triangular logits to −∞, ensuring next-token predictions depend only on past context.
Rather than performing a single attention function, Multi-Head Attention linearly projects Q, K, V into h different subspaces, allowing the model to jointly attend to syntax, coreference, and semantics simultaneously.