Transformer basics
An applied AI scientist interview on attention, positions, masks, and the residual stack a transformer is built from.
These prompts are original practice. They are not questions from a named employer or a live hiring loop.
1.In scaled dot-product attention, what is the vector produced for one query?
2.Before the softmax, what is the score between one query and one key?
3.In one head of self-attention, what does the matrix of query-key products contain?
4.Which pair of vectors sets how much one position attends to another?
5.In the attention formula, what is d_k?
6.After the attention weights multiply the values, what is the shape of the result?
7.In self-attention, where do queries, keys, and values come from?
8.Why does a full attention score matrix grow quickly as the sequence gets longer?
9.How does a hidden vector become a query, a key, and a value?
10.Are the query, key, and value projection weights different at each position?
11.What job does each of query, key, and value do?
12.Which widths must match for a query-key score to be defined?
13.In cross-attention, which stream is projected into queries, and which into keys and values?
14.After attention heads produce their outputs, what returns the result to the model width?
15.For one query, the attention softmax is a distribution over what?
16.Do two queries in the same head share a single set of attention weights?
17.Does the attention softmax pool probability across heads?
18.A score was set to negative infinity before the attention softmax. What is its weight afterward?
19.What does the attention softmax force to sum to one?
20.Assume query and key entries are independent, with mean zero and variance one. What is the variance of their dot product?
21.Why are query-key scores divided by sqrt(d_k)?
22.What happens if the 1/sqrt(d_k) factor is removed and d_k is large?
23.Why divide by the square root of d_k rather than by d_k itself?
24.When several heads split the model width, which length is used in the attention scale?
25.What does multi-head attention run inside a single sublayer?
26.What does a layer gain from several heads instead of one attention pattern?
27.Which procedure is multi-head attention?
28.If the model width stays fixed, what does the usual head split do when you add heads?
29.Heads and extra blocks both add capacity. Which change do heads actually make?
30.When can different heads in the same layer exchange information?
31.What does a causal attention mask prevent?
32.Which query-key pairs does a causal mask leave unblocked?
33.How is a causal mask inserted into the attention calculation?
34.Is the causal mask a trained parameter?
35.A later real token and an earlier pad are both in the sequence. Which one does a causal mask block?
36.Why are pad positions added to a batch of sequences?
37.What should a padding mask do when a pad position is used as a key?
38.Does the padding id have a row in the token embedding table?
39.A decoder batch holds sequences of different lengths. Which masks does its self-attention need?
40.How are pad positions usually treated by the next-token loss?
41.There is no positional encoding and no position bias. You reorder the input tokens. What does self-attention do?
42.How does an absolute positional encoding enter the model?
43.What stops a learned absolute position table from serving an arbitrarily long sequence?
44.How is a sinusoidal absolute position vector built?
45.Where does a relative position bias enter the calculation?
46.The same token id sits at two indexes under absolute position vectors. What do those inputs share?
47.What does a linear distance bias add inside attention?
48.How does rotary position encoding put order into the attention score?
49.What does a residual attention sublayer return?
50.How does the residual skip help a gradient reach early layers?
51.The branch of a residual block outputs the zero vector. What does the block return?
52.In a standard transformer block, which sublayers are added back onto the stream?
53.Why must the attention branch match the residual stream in width?
54.Layer norm in a transformer computes its statistics over which axis?
55.Why is layer norm a better default than batch norm for token sequences?
56.In the original block, what does layer norm receive?
57.When the norm sits on the branch input, what is added to the skip path?
58.After layer norm has made a token zero-mean and unit-variance, which learned parameters still apply?
59.Why does a pre-norm stack often apply one more layer norm just before the output head?
60.How does the feed-forward sublayer treat two different positions?
61.What is the shape of the original feed-forward sublayer?
62.Inside one block, which sublayer mixes positions, and which mixes channels?
63.In a classic block with feed-forward width four times the model width, where do more weights sit?
64.Is the feed-forward sublayer a convolution over neighboring tokens?
65.At inference, how does a token id become the vector that enters the first block?
66.How does an embedding lookup relate to multiplication by a one-hot vector?
67.How is a token embedding different from a one-hot encoding of the same id?
68.What does the output head produce from the final hidden vector?
69.What has to happen before a raw string can enter the transformer?
70.Does the embedding row for a token id depend on the other tokens in the sentence?
71.What loss trains a transformer to predict the next token?
72.The target puts mass 1 on the correct token. What does the cross-entropy equal?
73.In next-token training, what is the hidden state at position t trained to predict?
74.For softmax cross-entropy, what is the gradient with respect to the logits?
75.Is next-token cross-entropy the same objective as squared error between logits and a one-hot vector?
76.A language-model transformer applies softmax in two places. What is each distribution over?
77.What does label smoothing do to the training target?
78.When you decode by argmax or by sampling, do you still smooth a label?
79.How is label smoothing different from dropout?
80.What is true of the derivative of the logistic sigmoid?
81.Why can a deep stack of sigmoid units lose the gradient at early layers?
82.For a ReLU whose input is positive, what is the local derivative?
83.What happens to the gradient through a ReLU whose input is negative?
84.You add the same constant to every vocabulary logit. What happens to the softmax?
85.Why does a constant added to every logit cancel inside the softmax?
86.Why may code subtract the largest logit before exponentiating and still get the same softmax?
87.Sampling temperature rescales the vocabulary logits before the output softmax. Does the distribution stay fixed, as it does for an added constant?
88.Under inverted dropout, what does a training step do to a unit?
89.Under inverted dropout, what does evaluation do?
90.What happens if dropout is left in training mode while you score inputs?
91.Is a dropout mask part of the saved model?
92.In the usual residual block, where does dropout sit relative to the skip connection?
93.An encoder-only layer has no causal ban. Which keys are legal for a token?
94.A decoder-only model has a single stream. What may a token use as keys?
95.In an encoder-decoder model, what does a decoder query attend to in cross-attention?
96.Do encoder layers attend to tokens on the decoder side?
97.Why is a bidirectional attention pattern the wrong mask for next-token training?
98.What is the context length of a transformer?
99.A model uses a learned table of absolute position vectors. What does the table imply for context length?
100.During decoding, what does a key-value cache hold?
101.How is context length different from batch size?
102.For a causal model, what does the context length bound?
103.What does a checkpoint need to contain for you to run the model, and what is absent?
104.Which of these would you load from a weight checkpoint?
105.A training save holds Adam's moving averages along with the weights. What does a forward pass need?
106.Dropout is off and the weights are fixed. The forward pass is a fixed function of what?
107.In the scaled dot-product formula, is 1/sqrt(d_k) a trained parameter?
108.What does a position index count?