Question presented to candidate: "Walk me through the transformer. What happens to a sentence from the moment it is tokenized until the model outputs the next token, and what exactly is attention computing?"
What a strong answer should cover:
- The pipeline: token embeddings plus position information, a stack of identical blocks (multi-head self-attention, then a feed-forward network, each wrapped in a residual connection and normalisation), then a projection to logits over the vocabulary
- Attention itself: each token produces a query, a key and a value; scores are query-key dot products scaled by the square root of the key size, softmax turns each row into weights, and the output is the weighted sum of values: softmax(QKแต/โd_k)V
- Why it works: every token can pull information from any other token in one step, and all positions are computed in parallel, unlike an RNN
- The causal mask in decoder-only (GPT-style) models, and the three families: encoder-only, encoder-decoder, decoder-only
- Multi-head attention, and why position must be injected (attention alone ignores order) with sinusoidal, learned or rotary (RoPE) encodings
- The cost: attention scores grow with the square of sequence length, which is what makes long context expensive and motivates the KV cache and efficient attention kernels
Code / implementation expected: Optional โ computing attention for a few tokens by hand (or in a few lines of code) is the best proof of understanding.