Exercises

Practice permutation equivariance, absolute-vector addition, sinusoidal values, signed relative offsets, clipping, RoPE rotations and offsets, ALiBi softmax, and valid-shape position audits.

These exercises test reordering, absolute and relative position calculations, RoPE geometry, ALiBi scores, and position audits. Each prompt states its index and sign conventions.

Reordering and Absolute Position

Q1. Name the reordering property

An unmasked content-only self-attention layer satisfies f(PX)=Pf(X)f(PX)=Pf(X) for every row permutation matrix PP. Which property does this equation state?

Choose one

Select one choice, then check.

Hint
An invariant output would not contain the leading PP.
Solution
The equation states permutation equivariance.
Not attempted
Review

Not marked done.

Q2. Reorder an unmasked output

An unmasked content-only layer returns rows f(X)=[a,b,c]f(X)=[a,b,c]. The input rows are reordered from [0,1,2][0,1,2] to [2,0,1][2,0,1]. What output row order follows from permutation equivariance?

Choose one

Select one choice, then check.

Hint
Select output rows 2, 0, and 1 in that order.
Solution
The output is [c,a,b][c,a,b].
Not attempted
Review

Not marked done.

Q3. Add an absolute position vector

A repeated token has embedding e=[1,2,0]e=[1,2,0]. At index 4 its learned position vector is p4=[0.5,0.25,1]p_4=[-0.5,0.25,1]. What is the second coordinate of e+p4e+p_4?

Compute it first, then check your number.

Hint
Add corresponding coordinates.
Solution
e+p4=[0.5,2.25,1]e+p_4=[0.5,2.25,1], so the requested coordinate is 2.252.25.
Not attempted
Review

Not marked done.

Q4. Calculate one sinusoidal value

For dmodel=4d_{model}=4, the first sine coordinate is PE(pos,0)=sin(pos)PE(pos,0)=\sin(pos). What is PE(0,0)PE(0,0)?

Compute it first, then check your number.

Hint
The position is the angle for the first pair.
Solution
PE(0,0)=sin(0)=0PE(0,0)=\sin(0)=0.
Not attempted
Review

Not marked done.

Relative Offsets and RoPE

Q5. Apply the offset convention

Relative offset is defined as key index minus query index, jij-i. A query at index 8 reads a key at index 5. Which offset is used?

Compute it first, then check your number.

Hint
Substitute j=5j=5 and i=8i=8.
Solution
ji=58=3j-i=5-8=-3.
Not attempted
Review

Not marked done.

Q6. Clip a relative offset

A relation table clips jij-i to [4,4][-4,4]. The original offset is 9-9. Which table offset is selected?

Compute it first, then check your number.

Hint
Clamp the value to the nearest boundary.
Solution
The selected offset is 4-4.
Not attempted
Review

Not marked done.

Q7. Rotate a coordinate pair

Using R(ϕ)=[cosϕsinϕsinϕcosϕ]R(\phi)=\begin{bmatrix}\cos\phi&-\sin\phi\\\sin\phi&\cos\phi\end{bmatrix}, rotate [0,2]T[0,2]^T by ϕ=π/2\phi=\pi/2. What is the first coordinate?

Compute it first, then check your number.

Hint
At π/2\pi/2, cosine is 0 and sine is 1.
Solution
The rotated vector is [2,0]T[-2,0]^T, so the first coordinate is 2-2.
Not attempted
Review

Not marked done.

Q8. Compare equal RoPE offsets

The same unrotated query and key pair uses the same RoPE frequency. Which two position pairs must produce the same pairwise RoPE dot product?

Choose one

Select one choice, then check.

Hint
The identity depends on key position minus query position.
Solution
The pairs (1,4)(1,4) and (7,10)(7,10) both have offset 3.
Not attempted
Review

Not marked done.

Score Bias and Integrated Audit

Q9. Normalize an ALiBi row

A causal query has four equal content scores. ALiBi adds biases [1.5,1.0,0.5,0][-1.5,-1.0,-0.5,0]. What is the softmax weight on the final key? Give at least three decimal places.

Compute it first, then check your number.

Hint
Use stable softmax; subtracting the maximum 0 leaves the same four values.
Solution
The denominator is e1.5+e1+e0.5+12.1975e^{-1.5}+e^{-1}+e^{-0.5}+1\approx2.1975, so the final weight is 1/2.19750.4551/2.1975\approx0.455.
Not attempted
Review

Not marked done.

Q10. Audit a valid-shape position mismatch

Training uses left padding and assigns the first real token position 0. Evaluation also uses left padding but assigns physical column indices, so the first real token may receive position 3. All input, mask, and output shapes match. Which audit is most direct?

Choose the audit

Select one choice, then check.

Hint
Inspect values at the boundary where tokens acquire position IDs.
Solution
Print and compare the token-to-position mapping. Training and evaluation must use the same declared padding and index policy.
Not attempted
Review

Not marked done.

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.

0 of 10 exercises marked done

Review

Not marked done.