Exercises
Practice encoder and decoder masks, padding, corrupted inputs, shifted targets, leakage diagnosis, cross-attention sources and shapes, family selection, and specification audits.
Use explicit sequences, axes, and shift conventions. Do not answer from family names alone.
Q1. Construct encoder visibility
Write the visibility matrix for a non-padded encoder input A B C
under full self-attention.
Answer it first, then check.
Hint
Solution
Q2. Construct decoder visibility
Write the second row of an inclusive left-to-right causal visibility matrix for four positions.
Compute it first, then check your number.
Hint
Solution
Q3. Separate padding masks
In a length-five encoder record, positions 4 and 5 are padding. How many key columns may a real query read, and should padded query positions contribute to the task loss?
Answer it first, then check.
Hint
Solution
Q4. Align masked-token evidence
The clean input is red fox runs; the model input is red <mask> runs. Which
token is the selected target, and may its query use runs under full encoder
self-attention?
Answer it first, then check.
Hint
Solution
fox, and its query may use runs.Q5. Build shifted decoder targets
For tokens A B C D, an input tensor contains A B C. Write its next-token
target tensor.
Answer it first, then check.
Hint
Solution
B C D.Q6. Detect decoder leakage
Changing future token D changes the logits used to predict B. Name the
violated contract and the first two places to inspect.
Select one choice, then check.
Hint
Solution
Q7. Assign cross-attention sources
In encoder-decoder cross-attention, which records supply , and which supply and ?
Select one choice, then check.
Hint
Solution
Q8. Derive all attention score shapes
For , , , and , give encoder self-attention, decoder self-attention, and cross-attention score shapes.
Answer it first, then check.
Hint
Solution
Q9. Choose a family without overclaiming
A task needs one contextual output per input token, with both left and right context available. Name the natural starting family and state whether it is the only architecture that could be adapted.
Answer it first, then check.
Hint
Solution
Q10. Audit a family specification
A document says only “T5-like Transformer.” List four additional facts needed to reconstruct its information flow and learning target.
Select one choice, then check.