Causal Attention Mask
An autoregressive position may read its prefix, including itself, but never later tokens. Mask before softmax and normalize each allowed row.
row = 1
print([column <= row for column in range(3)])From arithmetic to an experiment
An autoregressive position may read its prefix, including itself, but never later tokens. Mask before softmax and normalize each allowed row. The trace reads the local variables of your function as it executes. Change one input or parameter, predict the result, then run the checks again. A small deterministic example makes arithmetic mistakes easier to locate than a long training run. State the shape and meaning of the returned value before coding. Keep preprocessing, evaluation and model updates in their proper order, and examine the boundary case in each check. The companion lab lets you replay intermediate values while the same algorithm runs.
Your task
causal_weights(scores) takes a square nonempty score matrix and returns row softmax with columns j > i set to probability zero. Use stable exponentials over the unmasked prefix.
The explanation opens here once every check passes.