Skip to content
mentoor

Topic 3 of 5 · 4 min read

Many attention heads across layers

Goal: Describe what multiple heads and stacked layers add and identify the pattern a head follows in an attention visualizer.

One attention step gives one pattern of who reads from whom; a transformer runs many heads side by side in each layer and stacks many layers, so it can learn many patterns at once and build on earlier ones.

Check yourself · 1 of 3

What is the main benefit of using many attention heads in a layer?

Choose one answer

Why it matters

A single attention pattern per token is too coarse. In "The lawyer told the client that she would file on Monday", a model may need one view for who "she" is, another for what "file" means, another for syntax. If you debug with an attention visualizer, you need to know what a head can and cannot show you.

Heads: several small lookups in parallel

Multi-head attention splits the work. Instead of one big query, key and value, the model makes several smaller sets, each called a head. Each head has its own learned matrices, computes its own weights and produces its own output. The outputs are joined and mixed by one more matrix. The original transformer paper used 8 heads per layer.

Splitting does not cost much extra compute, because each head works on a smaller slice of the vector. What you gain is variety: different heads are free to specialise.

What single heads tend to learn

Researchers who inspect trained models report heads with recognisable habits:

  • Previous-token heads attend mostly to the token just before.
  • Syntax heads link a verb to its subject or a closing bracket to its opener.
  • Reference heads link a pronoun to a likely noun.
  • Copy or repeat heads find an earlier occurrence of the current token and attend to what followed it. This is part of how models continue a pattern from the prompt.

Many heads look messy or redundant. Not every head has a neat human label.

Layers: building on earlier layers

Each layer takes the outputs of the one below. Early layers tend to capture local, surface patterns (neighbouring words, punctuation). Later layers can combine those into more abstract relations, because their inputs already carry information from other positions. Depth lets "it" first be linked to "server", then that enriched vector be linked to a fact about servers.

Before and after

Weak: "The model has one attention that finds the important words." Better: "The model has dozens of layers with many heads each. Every head shows one pattern, and the answer comes from all of them combined, layer after layer."

What goes wrong

  • Over-reading a single head. One clean pattern in a visualizer is a hint, not an explanation of the whole output.
  • Assuming one head per skill. Behaviours are spread across many heads and layers; removing one head rarely removes a skill.
  • Mixing up heads and layers. Heads run in parallel inside a layer. Layers run in sequence.

Examples

Reading a visualizer

Head What it attends to Likely role
Layer 2, head 3 the token right before previous-token head
Layer 5, head 1 a closing ) looks at its opening ( syntax head
Layer 9, head 7 the second "Alice" looks at what followed the first "Alice" copy head

Each row is one head. The label is a human guess from the pattern, not something the model reports.

Heads in parallel, layers in sequence

A model with 12 layers and 12 heads per layer computes 12 patterns at once in each layer, then passes the combined result to the next. That is 144 heads in total, but only 12 steps of depth. Making a model deeper adds steps; adding heads adds parallel views.

Key points

  • A head is one small attention computation with its own query, key and value matrices; a layer runs many heads in parallel.
  • Different heads can specialise: previous-token, syntax, reference and copy patterns are commonly reported.
  • Layers run in sequence, so later layers build on information that earlier layers already moved between positions.
  • Splitting into heads adds variety without much extra compute, because each head uses a smaller slice of the vector.
  • A pattern seen in one head in a visualizer is a clue, not a full explanation of the model's answer.

Common mistakes

  • Explaining a model's answer from one attention head in a visualizer.
  • Believing each head owns one clean skill that could be switched off alone.
  • Confusing heads (parallel, inside a layer) with layers (sequential, stacked).
  • Treating human labels like "syntax head" as facts the model reports, rather than guesses from observed patterns.

Check yourself · 2 of 3

In an attention visualizer, one head sends most of its weight from each token to the token directly before it. What kind of head is it?

Choose one answer

Check yourself · 3 of 3

How do heads and layers differ?

Choose one answer

Practice items, not counted towards your mastery.

Start here