Transformers and Attention Questions

The transformer architecture behind modern language models. Covers queries, keys and values, scaled dot-product and multi-head attention (including why scores are scaled and worked numeric examples), masking, positional encoding (sinusoidal, learned, relative with bucketed biases, rotary, and 2D schemes for image patches), encoder-only, decoder-only and encoder-decoder variants, residual connections, layer normalization placement and the feed-forward block, parameter, memory and compute accounting, why transformers scale better than recurrent models, efficient and long-context attention variants (sparse, local window with global tokens, hashing-based, linear, low-rank, FlashAttention, multi-query), and what attention heads learn and what raw attention weights do and do not explain. Includes implementing attention and its components from scratch. Distributed training, serving and quantization, fine-tuning, pretraining objectives, and general optimizer practice are covered elsewhere.

MediumTechnical
28 practiced

Raw attention weights are often shown as explanations of a Transformer's prediction. What do individual heads in multi-head attention tend to learn, why can raw attention weights be a misleading explanation of the output, and what complementary methods (head ablation, gradient-based attribution, causal interventions, probing) would you use to check an interpretation?

MediumTechnical
39 practiced

Self-attention costs O(n^2) in time and memory. Explain why, then lay out the main ways to reduce that cost for long sequences and the accuracy trade-off of each.

EasyTechnical
37 practiced

What is the basic intuition behind self-attention, and why did Transformers become the dominant architecture for modern language models?

EasyTechnical
35 practiced

What roles do residual connections and layer normalization play in a Transformer block? Contrast pre-norm and post-norm placement briefly.

EasyTechnical
29 practiced

Compute single-head attention by hand for a tiny example (two tokens, d_k = 2, given Q, K and V). Show the score matrix, the scaling, the row-wise softmax and the final output, and say what each attention row means.

Unlock Full Question Bank

Get access to all 31 Transformers and Attention interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.