Whenever you're ready, walk me through how you'd approach this.
Can you explain the self-attention mechanism inside a transformer?
Describe how token embeddings become queries, keys, and values, derive the scaled dot-product attention equation, and explain why scaling, positional information, residual connections, and normalization are needed. Demonstrate the mechanism in PyTorch, including padding or causal masking, and show how attention weights are computed and evaluated. Discuss computational complexity, multi-head attention, and at least one failure mode or implementation pitfall.