Zenaique

Describe the W_O projection in multi-head attention, its shape and what it mixes.

Flashcard·Easy·4.0 · 0·~30s·Asked atCognizantLangChainWandb·Relevant atMicrosoft
Attempt it
TL;DR

W_O is the (d_model, d_model) output projection after head concat. Its job is to mix signals across heads before the residual add.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture eight reporters who each cover a different beat at a city paper, sports, weather, politics, food. Each writes one column independently. Without an editor, the front page would just be eight separate columns sitting side by side, with no story that crosses beats. W_O is the editor who reads all eight columns and weaves them into one front page, where the sports story can pull in a quote from the politics column and the food story can reference the weather. The shape of the front page is the same with or without the editor, but the story is much richer when the editor gets to mix the contributions.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

The output projection W_O sits at the end of every multi-head attention sub-layer in every modern transformer. Its shape (d_model, d_model) does not change the dimensionality of the data flowing through, which makes it tempting to dismiss as 'plumbing'. The dismissal is wrong: W_O is the only place where the per-head outputs of multi-head attention can mix with each other, and it is the substrate that makes multi-head behave as more than h independent attention computations stacked side by side.

This deep dive walks the slice structure that motivates W_O, explains the per-head decomposition view that makes the mixing concrete, surveys the empirical evidence from interpretability research, and closes with how W_O fits into the broader residual-stream picture.

Mental model: W_O is the editor that turns h independent reporters into one coherent front page.

Where W_O sits in the attention sub-layer

The full multi-head attention sub-layer is a sequence of operations:

  1. Project the input x into Q, K, V via W_Q, W_K, W_V.
  2. Split Q, K, V into h heads, each of width d_head = d_model / h.
  3. Compute scaled dot-product attention per head: head_i = softmax(Q_i K_i^T / sqrt(d_head)) V_i.
  4. Concatenate the h head outputs along the last axis to recover a d_model-wide vector.
  5. Apply W_O: out = W_O @ concat(head_0, ..., head_{h-1}).
  6. Add to the residual stream.

W_O sits at step 5, between the concat and the residual add. Its shape (d_model, d_model) matches the concatenated output's d_model width on both sides.

What the concat does

The concat is a memory rearrangement, not an arithmetic operation. It takes h separate d_head-wide context vectors and arranges them contiguously into one d_model-wide vector. Head 0's output occupies indices [0, d_head), head 1 occupies [d_head, 2*d_head), and so on.

No information flows across heads during the concat. Each head's output sits in its own slot, untouched.

Why the slice structure needs W_O to break it
The per-head decomposition view
Empirical evidence and the bottom line
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Every production decoder-only transformer (Llama 4 Maverick, GPT-5.5, Claude Opus 4.7, Gemini 3.1 Pro, Qwen 3.5) keeps W_O at full d_model x d_model rank.
  • Anthropic's transformer-circuits framework decomposes W_O into per-head write matrices for mechanistic-interpretability analysis.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QIf W_O is so important, why does removing the bias term on W_O usually not matter?
A

The bias on W_O adds a constant shift to the residual stream, which downstream layer normalization can absorb. The matrix W itself is what does the mixing; the bias term is a free parameter the model can mostly replicate via the LayerNorm gain and bias.

1 more follow-up an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Calling W_O a 'shape-preservation' bookkeeping step and missing that it is the only place where heads can mix with each other before the residual add.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Shape and position of W_O in the multi-head attention sub-layer

  • Why W_O is needed despite the input and output dimensions matching

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium