Compute Two Heads with Separate Projections
Calculate two causal heads from the same three-token input using separate projection matrices. The trace makes each score, softmax row, value reading, and difference between the two heads numerically visible.
Separate-head notation makes the calculation easiest to inspect. Each head has its own projection matrices and runs the single-head operation from Chapter 1.
Use one three-position sequence with model width 4:
There are two heads, with . Head 1 selects the first two input coordinates, and head 2 selects the final two:
For this trace, set
Head 1 Reads the First Coordinate Pair
The projected rows are
For the final query , the scaled scores are
Stable softmax gives approximately
The reading is
Head 2 Reads the Final Coordinate Pair
The second projection gives
For the final query , the scaled scores are
Its weights are approximately
and its reading is
The two heads received the same input rows and used the same causal visibility rule. Their projections produced different queries, keys, values, weights, and readings.
Concatenate the Results
Joining the head features in head order gives
For now, let , so this vector is also the final layer output. Lesson 5 will use a non-identity and show why head order is meaningful only together with the corresponding blocks of that projection.
Trace two heads separately
The program projects, scores, normalizes, and reads each head independently. Change one projection and compare both weight rows.
Ready to run.
Q1. Calculate one head coordinate
Head 1 has weights approximately and values , , and . What is the first coordinate of its reading to three decimal places?
Compute it first, then check your number.
Hint
Solution
Compare Heads Before Averaging Them Away
When inspecting multi-head attention, retain the head axis long enough to compare its scores, weights, and values. Averaging attention maps across heads can hide the very differences the architecture permits.