Quiz: attention, transformers and pretrained models

Short questions to test your understanding. Try each on paper first, then open the answer.


Q1. In one sentence each: how does a 3 \times 3 convolution combine pixels, and how does self-attention combine tokens?

Where do the weights come from?

A convolution takes a weighted sum of the 9 neighbours with fixed learned weights that depend only on the relative position and are the same everywhere. Self-attention takes a weighted average of all tokens, with weights computed from the content (how well each token’s key matches the query) and normalised to sum to 1.


Q2. Scores 2, 0, 0 for three values 6, 3, 0. Compute the attention output.

Softmax: e^2, e^0, e^0 normalised.

Weights e^2/(e^2 + 2) = 0.787, and 0.106 twice. Output 0.787 \cdot 6 + 0.106 \cdot 3 + 0 = 5.04.


Q3. Why does a transformer without position codes not know where a patch is in the image?

Shuffle the patches.

Attention treats the tokens as a set: shuffling the input only shuffles the output in the same way (permutation equivariance). Nothing in the computation depends on the order, so the arrangement of the patches is invisible unless a position code is added to each token.


Q4. Halving the patch size of a transformer multiplies the number of attention weights per layer by how much?

Number of tokens, then its square.

Four times as many tokens, so 4^2 = 16 times as many weights.


Q5. You have 15 annotated images and a large pretrained network. Frozen features + a linear probe, or full fine-tuning? Why?

How many parameters are trained in each case?

Frozen features + a probe: only a few dozen parameters are trained, which 15 images can determine; full fine-tuning of millions of weights on 15 images overfits and can destroy the useful pretrained features.


Q6. A contrastive model was pretrained with strong brightness augmentation. Why is it a poor feature extractor for measuring the intensity of a stain?

What were the two views taught to agree on?

It was trained so that a crop and its brightened copy have the same embedding: brightness is exactly what it learned to ignore. The augmentations decide what the features are blind to.


Q7. A network says 0.99 for 1000 test images and is right on 920. Is it calibrated? What does temperature scaling with T > 1 do to its accuracy?

Compare confidence and accuracy.

No: confidence 0.99, accuracy 0.92: overconfident. Temperature scaling lowers the confidences but leaves the predicted classes, and so the accuracy (92 %), unchanged.


Q8. Temperature was fitted on validation data from microscope A. Will the network be calibrated on microscope B?

What changed between A and B?

Not necessarily: under domain shift the accuracy drops while the confidences need not, so the network is typically overconfident again. Calibration must be checked (and refitted) on data from B.


Q9. (math) Why is the dot product in attention divided by \sqrt d?

Variance of a sum of d independent products.

For queries and keys with independent unit-variance entries, \mathbf q^\top\mathbf k has variance d. Without scaling the scores grow with d and the softmax saturates (one token gets all the weight, gradients vanish); dividing by \sqrt d brings the variance back to 1.


Q10. Give two situations in which a classical method is the better choice than a deep network.

Data, prior knowledge, explanation.

For example: very few images or no annotations; a strong prior on the shape (circles, lines, a calibration grid) that a model fit uses directly; a measurement whose bias must be understood and explained; or when a simple classical pipeline already works on all the data.