Attention by shapes
The word-token pages teach what attention is for. This track teaches the shapes: every matrix labeled with live dimensions, so the picture is the arithmetic. Spec from Prof. Tom Yeh’s AI by Hand Attention library (byhand.ai) — redrawn in this site’s palette; dog metaphors left behind.
Worth having first: Queries, keys, values & heads.
- QKV Projection — Three learned maps turn one embedding matrix into questions, labels, and payloads.
- Attention Computation — Scores, shares, and the blended output — no new weights.
- Self Attention — Everyone asks, everyone can be found — S is N×N.
- Cross Attention — Queries from one sequence; keys and values from another.
- Self vs Cross — Same X asks both times; only where K and V come from changes the shape.
- Shared KV — Only Wq — Q is reused as the key.
- Multi-Head Attention — Several full heads, concat, then Wo.
- Fused QKV — One Wqkv, sliced into per-head Q/K/V.
- Single vs Multi-Head — Same width: H× more dots, same V×A multiplies.
- MQA (shapes) — One full KV drawer; the other heads only bring a query.
- GQA (shapes) — Groups of heads share a K/V set — the dial between MHA and MQA.