Hacker News front page11 min readintermediate
Transformers Explained Visually
Summary
The article walks through the core components of a text‑generative Transformer—embedding, multi‑head self‑attention, MLP, and output projection—using GPT‑2 small as a concrete example. It shows the dimensions, parameter counts, and step‑by‑step calculations that underlie token prediction.
- GPT-2 small uses 12 transformer blocks, each with 12 attention heads, 768‑dim embeddings, and a 4× expansion MLP (768→3072→768).
- The embedding matrix shape is (50,257,768) ≈ 39 M parameters; positional encodings are learned jointly.
- Self‑attention computes Q, K, V via linear projections, scales dot‑product, masks future tokens, then applies softmax to get attention weights.
- Multi‑head attention splits Q/K/V into 12 heads, enabling parallel capture of different syntactic and semantic relationships.
Anyone building, fine‑tuning, or debugging LLMs needs a clear mental model of the architecture’s shapes and operations.
6/10

