Presets:
Select Active Head (Multi-Head Self-Attention)
Token Direct Manipulation Click any token to set Query focus ($Q$)
Full $N \times N$ Attention Matrix ($\text{Softmax}(Q K^T / \sqrt{d_k})$) Rows = Queries ($Q$), Columns = Keys ($K$)

The 5 Stages of Transformer Computation

1
Tokenization & Positional Encoding

Unlike recurrent networks (RNNs) that process word-by-word sequentially, Transformers process all words concurrently. Positional vectors ($\sin$ & $\cos$ frequencies) are added to token embeddings so the model knows word order.

2
Query, Key, Value Projections

Each token vector is multiplied by three learned projection matrices: $W_Q$ (what it is looking for), $W_K$ (what it contains to match against), and $W_V$ (the actual information payload to pass forward).

3
Scaled Dot-Product Attention

The similarity score between Query $i$ and Key $j$ is computed as $q_i \cdot k_j / \sqrt{d_k}$. Softmax turns these raw logits into a rigorous probability distribution that sums to exactly 1.

4
Multi-Head Specialization

Multiple attention heads operate in parallel subspaces. One head tracks pronouns (e.g. resolving "it" to "animal"), another tracks direct objects, and another tracks subject-verb agreement.

5
Residuals & Feed-Forward (MLP)

The aggregated values $\sum \alpha_j V_j$ are added back to the input vector through a skip connection (LayerNorm), followed by a 2-layer Feed-Forward neural network that synthesizes high-level factual knowledge.