As asked
Explain how scaled dot-product attention computes its output. Why is the scaling factor of the square root of the key dimension necessary, and what would happen without it?
Sample answer outline
The candidate explains Q*K^T / sqrt(d_k) produces attention logits, softmax normalizes to attention weights, and those weights multiply V to produce the output. Without scaling, the variance of the dot products grows proportionally to d_k (the key dimension), which pushes logits into regions where softmax saturates and gradients vanish, making training unstable. Dividing by sqrt(d_k) returns the variance to roughly 1. They optionally mention multi-head attention and how it allows attending to different representation subspaces in parallel.
Expect these follow-ups
- What is the computational complexity of self-attention with respect to sequence length?
- How does flash attention reduce memory without changing the result?