Input Sequence & Tokenizer
Presets:
Tokens (click a token to focus its Query attention distribution):
Multi-Head Attention Routing Arcs
Softmax Attention Matrix $A = \text{softmax}(QK^T / \sqrt{d_k})$
Rows = Query (From), Cols = Key (To)
Projection Inspector: Query, Key, Value
Token: "it" (Index 7)
Attention(Q, K, V) = softmax( (Q · KT) / √dk ) · V
Softmax Temperature (T): 1.0
Scaling Factor (√dk): 8.0 (d=64)
Query (Q) "What am I looking for?"
Key (K) "What do I contain?"
Value (V) "Information provided"
Top Next-Token Generation Logits
The Transformer Forward Pass: Step-by-Step Architecture
Click a stage to understand its internal transformation
01
Tokenization & Embedding
02
Positional Encoding
03
Multi-Head Self-Attention
04
Add & LayerNorm + FFN
05
Linear Head & Softmax

1. Why Self-Attention Beat RNNs

Recurrent Neural Networks (RNNs & LSTMs) processed text sequentially from left to right, creating two severe bottlenecks: information decay over long context windows, and inability to parallelize across modern GPU clusters. Attention computes direct pairwise relationships between every token in O(1) sequential time.

2. Why Multi-Head Attention Matters

A single attention head can only focus on one type of relationship at a time. By projecting into multiple lower-dimensional subspaces (heads), one head tracks syntactic dependencies (verb-object), another resolves pronouns ("it" → "animal"), and another captures positional adjacency.

3. Scaled Dot-Product & √d_k

As the vector dimensionality $d_k$ grows large, dot products increase in magnitude, pushing the softmax function into regions with near-zero gradients (vanishing gradient problem). Dividing dot products by $\sqrt{d_k}$ keeps variance at 1.0 and stabilizes gradient flow during backpropagation.

Enjoy this tool? Build your own with Super