Practice deriving self-attention shapes, calculating projections and masked weights, applying W_O, diagnosing axis and batching errors, counting parameters, and bounding interpretation claims.
These exercises move from shapes and individual calculations to debugging and
evidence. Each prompt contains the values and conventions it needs.
Read and Derive Shapes
Q1. Complete the shape trace
A batch-major single-head layer uses B=4, T=12, dmodel=8, dk=3,
and dv=5. What is the shape of the attention reading H=AV?
Select one choice, then check.
Hint
For each batch item, (T,T)(T,dv)=(T,dv).
Solution
H has shape (4,12,5). The output projection will later map its
last axis from 5 to dmodel=8.
Q2. Derive the output-projection shape
The same layer produces H with shape (4,12,5) and must return Y with
shape (4,12,8). What shape must WO have?
Select one choice, then check.
Hint
Complete (4,12,5)(?,?)=(4,12,8).
Solution
WO:(5,8).
Calculate the Operations
Q3. Project one query
Let x=[2,−1] and
WQ=[102−1].
What is the second coordinate of q=xWQ?
Compute it first, then check your number.
Hint
Multiply x by the second column of WQ.
Solution
q=[2,5], so its second coordinate is 5.
Q4. Normalize an allowed causal row
A causal query has two allowed scores, [ln3,0], followed by one forbidden
future score. What are the three attention weights after masking and softmax?
Select one choice, then check.
Hint
eln3=3 and e0=1.
Solution
The allowed weights are 3/(3+1)=0.75 and 1/(3+1)=0.25.
The forbidden future weight is 0.
Q5. Finish the value and output calculation
Weights are [0.75,0.25], values are v1=[2,0] and v2=[0,4], and
WO=[1012].
What is the second coordinate of y=(0.75v1+0.25v2)WO?
Compute it first, then check your number.
Hint
Compute h first, then multiply it by the second column of WO.
Solution
h=0.75[2,0]+0.25[0,4]=[1.5,1]. Its second projected coordinate is
1.5(1)+1(2)=3.5.
Diagnose and Repair
Q6. Find the wrong axis
An attention matrix is
A=[0.80.20.30.7].
Its columns sum to 1, but its rows do not. Which implementation error best
explains the matrix?
Select one choice, then check.
Hint
Each query needs one distribution over keys.
Solution
Softmax used the wrong axis. It must normalize each row across its
key-position columns.
Q7. Detect cross-batch mixing
A batch contains sequences A and B. After changing only one token in B, the
output for A also changes. All model parameters are fixed and there is no
batch-dependent normalization. What does this observation establish?
Select one choice, then check.
Hint
A deterministic per-sequence operation must preserve independence between
batch items.
Solution
The batch dimension was likely transposed, flattened, normalized, or
multiplied incorrectly. Changing B must not alter A under the stated layer.
Count and Interpret Carefully
Q8. Count projection parameters
A bias-free single head has dmodel=8, dk=3, and dv=4. Count all
entries in WQ, WK, WV, and WO.
Compute it first, then check your number.
Hint
Count each matrix separately, including the map from dv back to
dmodel.
Solution
24+24+32+32=112 parameters.
Q9. Bound an interpretation claim
For one prediction, position 7 receives the largest attention weight in one
head. Which conclusion is justified by that observation alone?
Select one choice, then check.
Hint
Values, output projections, residual paths, and later layers have not been
examined.
Solution
The supported claim is only that the value at position 7 received the
largest scalar multiplier in that attention row and head. Causal or reasoning
claims require additional evidence.
Integrated Audit
Q10. Specify a complete layer audit
A colleague reports only the final output shape of a new causal self-attention
implementation. Choose the smallest audit below that checks the chapter's main
failure modes.
Select one choice, then check.
Hint
Prefer checks that can locate the first incorrect intermediate.
Solution
The complete audit is required. It checks the computation in
dependency order and separates observed tensors from interpretation.
Pause and reflect
Which exercises were difficult, what mistake pattern did you notice, and what should you practice again? The note stays with this exercise set.