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.

EasyTechnical
40 practiced

What is the position-wise feed-forward network in a Transformer block for? Describe its dimensions and activations, and how it contributes to capacity and non-linearity compared with attention.

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.

MediumTechnical
58 practiced

Explain relative positional encodings as used in T5 and Transformer-XL. What are the memory and compute costs, how do bucketed and exact relative distances differ, and how do they affect generalization to longer sequences?

EasyTechnical
37 practiced

Explain self-attention in a Transformer: what queries, keys and values are, how the output is computed from them, why the scores are scaled, and what shapes flow through the computation for a batch of sequences.

MediumTechnical
41 practiced

Compare locality-sensitive-hashing attention with fixed sparse patterns and sliding-window attention. How does each reduce memory and compute, and what are the weaknesses?

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.