Query & Key Dot Product
q₈ · k₁
Attention(Q, K, V) = softmax( (Q · Kᵀ) / √dₖ ) · V
Query (Q) Vector
Token #8 "it"
[+0.42, -0.18, +0.91, -0.05, ...]
Key (K) Vector
Token #1 "animal"
[+0.38, -0.15, +0.87, -0.02, ...]
1. Raw Dot Product (q · k):
+4.28
2. Dimension scaling (√dₖ = √16 = 4.0):
+1.07
3. Temperature applied (τ = 1.00):
+1.07
4. Softmax Attention Weight (α):
0.642 (64.2%)
5. Weighted Value contribution (α · v):
Norm: 0.81
Multi-Head Concatenation & W_O
MultiHead(Q,K,V) = Concat(head₁, head₂, head₃, head₄) · Wᴼ
Each head projects tokens into distinct representational subspaces. Head 1 tracks Coreference, Head 2 captures Grammatical Modifiers, Head 3 preserves Positional Proximity, and Head 4 connects Topical Associations.
Head 1 (Coreference) top target:
"animal" (64.2%)
Head 2 (Syntactic) top target:
"tired" (41.0%)
Head 3 (Positional) top target:
"was" (78.4%)
Head 4 (Semantic) top target:
"cross" (36.5%)
Linear Projection Out (Wᴼ):
Dimension: [N × 64]
Feed-Forward Layer (FFN) & Add+Norm
FFN(x) = max(0, xW₁ + b₁)W₂ + b₂ [or SwiGLU]
While self-attention allows tokens to communicate with each other, the FFN is applied to each token position individually. This is where the model stores factual knowledge and expands representations into higher dimensions (typically 4× the model dimension).
Input Dimension (d_model):
64 hidden units
FFN Expansion Dimension (4 × d):
256 units (GELU/Swish)
Residual Connection:
x + Sublayer(x)
LayerNorm Output:
Mean: 0.00, Var: 1.00
Vocabulary Logits & Probabilities
P(w | context) = softmax( h_final · W_unembedᵀ )
The final contextualized token representation is multiplied by the unembedding matrix to produce logits across the dictionary, normalized into completion probabilities.