Hover or click over any token above to isolate its attention arcs. Arcs represent how strongly each token (Query) queries every other token (Key).
Row = Query token ($q_i$), Column = Key token ($k_j$). Each row sums to $1.00$ ($\sum_j \alpha_{ij} = 1$) via Softmax.
Input Token & Pos Embeddings
Tokens are mapped to $d_{\text{model}}$ vectors and added to sinusoidal/learned positional encodings.
Q, K, V Projections
Each token vector is projected via matrices $W^Q, W^K, W^V$ across $h$ distinct attention heads.
Scaled Dot-Product & Softmax
Scores $S = \text{Softmax}\left(\frac{Q K^T}{\sqrt{d_k}}\right)$ compute pairwise contextual affinity.
Value Weighted Sum & Concat
Head outputs $\mathbf{head}_i = S_i V_i$ are concatenated and projected through output matrix $W^O$.
Residual & LayerNorm
Skip connection: $x' = \text{LayerNorm}(x + \text{Attention}(x))$ prevents vanishing gradients.
Feed-Forward MLP
Two-layer position-wise dense network with GELU activation processes token features independently.