Gradivex
  • Home
  • Academy
  • Arena
  • Visualizer
  • Models
Log in
NLP & Transformers/The Transformer/Lesson 2

Multi-head attention

Module 3 · Lesson 2 of 5 · 7 min read
Theory

One spotlight has to choose

A single attention pass produces ONE weighting per token. But a token has several relationships running at once: "it" needs its antecedent, its verb, and its position in the phrase, simultaneously. One softmax must average those needs into a single compromise pattern, and compromises blur.

The fix is almost insultingly direct: run several attention operations in parallel, each with its own Q, K, V matrices, each free to specialize. Every parallel copy is called a head. GPT-2 small runs 12 heads per layer across 12 layers: 144 independent spotlights sweeping the same text for different things.

No head is told what to specialize in. Training pressure alone differentiates them, the same way neurons in your CNN protocol ended up as edge detectors nobody designed.

Interactive

Three heads read one sentence

The full attention matrix of three (stylized) heads on the same sentence: each row is one word deciding where to look, brighter cell = more weight. Switch heads and watch the pattern reorganize.

This head lights up almost nowhere, except where a pronoun needs its antecedent.

Therobotpickeduptheballbecauseitwasheavy
The
robot
picked
up
the
ball
because
it
was
heavy

Click a row: each row is one word deciding where to look.

Theory

What real heads actually learn

The three heads you just used are cleaned-up archetypes, but they are drawn from reality. When researchers dissected trained transformers, they found:

  • Positional heads: attend to the previous token, or two back, or the start of the sentence.
  • Syntactic heads: track subject-verb, verb-object, preposition attachments, with surprising precision.
  • Rare-token heads: lock onto unusual words, useful for copying names and codes.
  • Induction heads: find earlier occurrences of the current pattern and predict "same thing as last time", a mechanism believed central to in-context learning.

And a bucket of heads that do nothing identifiable: prune them and the model barely notices. Training buys capacity in bulk and does not spend it all. The honest summary: multi-head attention is not twelve neat specialists, it is a mob of learned patterns, some sharp, some redundant, whose UNION covers the relationships language needs.

After every head has gathered its evidence, the results are concatenated and passed through one more learned matrix that decides how much of each head's opinion survives. Specialists propose, the projection disposes.

Interactive

Check your understanding

Why run 12 parallel heads instead of one attention pass with 12x the capacity?

Takeaway

What to remember

  • ✓One attention pass = one weighting pattern = a forced compromise between a token's many relationships.
  • ✓Heads are independent attention operations with their own Q, K, V, running in parallel on the same text.
  • ✓Specialization is emergent: position heads, syntax heads, induction heads, discovered, never assigned.
  • ✓Plenty of heads are redundant; the union of patterns is what matters, not per-head elegance.
  • ✓Concatenate, project, move on: the output is one enriched vector per token, ready for the next stage.
Mentor-0

Stuck on something in this lesson? Ask.

0/1000

Every lesson is free to read. Log in to save your progress, complete lessons, and earn Compute and XP.

Log in free
The attention mechanismPositional encoding
Gradivex

Understand AI from the inside, read it, see it, prove it.

Platform

AcademyVisualizerRoadmapsModels

Community

DiscordLeaderboard

Company

PrivacyTerms

© 2026 Gradivex. All rights reserved.