AnthropicCodingHalf AI-generated
Python codingWebAssembly + public tests
Reported interview periodSep 2025–Aug 2026
Implement Batched Scaled Dot-Product Attention
Implement attention for batched multi-head NumPy arrays on CPU. Inputs are finite arrays with the same floating-point dtype; dimensions are positive.
Practice focusShapes are q: (B, H, Tq, Dk) , k: (B, H, Tk, Dk) , and v: (B, H, Tk, Dv) . Return an array of shape (B, H, Tq, Dv) . When return weights=True , return (output, weights) , with weights of shape (B, H, Tq, Tk) . Requirements - Compute scores as q @ k.transpose(-2, -1) / sqrt(Dk) . - Apply softmax along the key-position dimension. - Support an optional boolean mask broadcastable to the score tensor, where false entries cannot receive probability. - Avoid numerical overflow by using a stable softmax or the framework's stable implementation.…