Attention vs convolution: compare them as inductive biases, and tell me what that implies for architecture choice.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Convolution hardcodes locality and translation equivariance with weight sharing. Attention hardcodes almost nothing and instead learns which positions interact, with mixing weights computed from the content itself.
Full worked answer
Convolution hardcodes locality and translation equivariance with weight sharing. Attention hardcodes almost nothing and instead learns which positions interact, with mixing weights computed from the content itself.
Mechanically: a conv layer applies a fixed kernel independent of input content over a fixed local window. Receptive field grows linearly with depth (exponentially with dilation), and parameter count is O(k·C_in·C_out) regardless of input size. Self-attention computes an input-dependent all-pairs mixing matrix: dynamic weights, global receptive field in a single layer, permutation-equivariant so position must be injected explicitly. The bill is O(n²·d) versus O(n·k·d).
The governing principle is the bias/data tradeoff. A strong prior is worth a great deal when data is scarce and costs you when data is abundant. Vision transformers underperform CNNs when trained from scratch on ImageNet-scale data and overtake them once pretrained on substantially larger corpora (DeiT later closed much of the small-data gap with heavy augmentation and distillation, which is just another way of supplying the prior), because the prior a CNN hands you for free is something attention can learn if you show it enough examples. That is the lesson of the last decade compressed into one comparison: general architectures plus scale beat hand-built priors past a data threshold, and below that threshold the prior wins.
Attention can express convolution (learn a local, position-only mask) but pays quadratic cost for the privilege. Which is why in practice everything converged on hybrids: conv stems and patchify layers in vision transformers, depthwise convolutions interleaved with attention in speech models, sliding-window and local attention in long-context LLMs. That last one is literally reintroducing the locality prior because the quadratic cost became the binding constraint. The state-space and linear-attention line does the same thing with a recurrent prior to recover O(n).
What this changes in my decisions: with thousands of examples and a strongly local signal, use a conv or a pretrained conv backbone. With a pretrained transformer available and long-range or content-dependent interactions, use attention. Data volume and the compute budget decide, not which architecture is currently fashionable.
What a good answer covers
- Convolution hardcodes locality and translation equivariance with weight sharing
- Attention hardcodes almost nothing and instead learns which positions interact, with mixing weights…
- Mechanically: a conv layer applies a fixed kernel independent of input content over a fixed local window
- Receptive field grows linearly with depth (exponentially with dilation), and parameter count is…
- Self-attention computes an input-dependent all-pairs mixing matrix
Key terms: bias/data tradeoff
In the glossary: Attention · Distillation
Interviewer follow-ups to expect
Sliding-window attention reintroduces locality. Does that make it strictly worse than full attention on quality, and how would you measure it?
Why is permutation equivariance a problem for attention but not for convolution?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep