NumPy allowed · plain Python earns 10 bonus points
Q · Kᵀ / √d scores normalized with softmax
Prevent autoregressive models from attending to future sequence tokens via upper-triangular masking.
Implement apply_causal_mask(scores, mask_val): for a square attention score matrix scores of shape (S, S), replace all upper-triangular elements scores[i][j] where j > i with mask_val. Keep elements where j <= i intact. Round all elements to 4 decimals.
apply_causal_mask(scores: list[list[float]], mask_val: float = -10000.0) -> list[list[float]]