4.2 — Equivariance, weight sharing, receptive fields
Goal: State translation equivariance precisely, prove convolution is the canonical translation-equivariant linear map, and quantify the receptive-field cost of seeing far through a stack of convs.
1. Why this session exists
Convolution isn't an arbitrary trick. It is, in a precise sense, the unique family of linear maps that respects translations of the input. Stating this carefully — and computing how far a stack of convolutions can see — is what makes the leap to attention in Chapter 6 motivated rather than mysterious. Two convolutions can see eleven pixels. Sixteen can see 65. To mix every pair of tokens in a 1024-long sequence, vanilla convolution forces depth that buys nothing else.
We do three things here:
- Define translation equivariance.
- Prove that 1D and 2D convolutions are translation-equivariant, and identify weight sharing as the reason.
- Compute receptive fields exactly and see the "depth tax" that motivates attention.[1]
2. Equivariance vs invariance
Let denote the translation operator that shifts an input by positions:
(For images, .)
A map is translation-equivariant if shifting the input shifts the output by the same amount:
It is translation-invariant if shifting the input doesn't change the output at all:
The slogan: equivariance preserves the "where"; invariance throws it away. A classifier that says "cat" no matter where the cat is in the image is invariant. A feature map that says "cat-snout-here" and moves the "here" along with the cat is equivariant. CNNs build up equivariance layer by layer, then a final global pooling step turns it into invariance.
[6]3. Convolution is translation-equivariant
We prove this for 1D; the 2D case is identical with two indices.
Claim. Let be 1D cross-correlation with kernel . Then .
Proof. Compute the left side directly:
The last expression is , which is . So
and equivariance is established.
The proof took one line because the convolution formula has the structure needed: the kernel only sees relative offsets between input and output positions, never the absolute position .
3.1 Why a generic linear map fails
A generic linear map has a matrix with no constraints. Equivariance would require for all — i.e. the matrix is constant along diagonals. A matrix constant along diagonals is exactly a Toeplitz matrix (1D) or a block-Toeplitz with Toeplitz blocks matrix (2D). And Toeplitz matrices acting on finite sequences are exactly discrete convolutions.
In other words: the space of linear translation-equivariant maps on is precisely the space of convolutions. Convolution isn't a good translation-equivariant operator; it is the one.
4. Weight sharing as the source
The proof in §3 says it cleanly: convolution is equivariant because depends only on the offset , not on the output position . The same numeric kernel is used at every output location.
This is called weight sharing, and it is the structural reason convolutions have parameters independent of . Each entry of is a parameter re-used at different output positions. The dense layer of 4.1 §5.1 had one parameter per output position; the conv layer ties them all together.
Weight sharing also enforces translation equivariance during learning: gradient updates to are sums over every output location, so the same kernel improves uniformly across the image. There is no way for the optimiser to "specialise" weights for the top-left corner versus the bottom-right.
[7, 8, 9, 10]5. Receptive fields
A neuron in a deep network responds to a region of the input — its receptive field. Larger receptive fields are needed to detect larger patterns and to mix information from far apart. The question: given a stack of convolutions, how big is the receptive field at depth ?
5.1 Definition and recursion
Index layers . Layer uses a kernel of size and stride . Define as the receptive field of a single neuron at depth , measured in input pixels.
At the input, (the identity).
After one conv with kernel (stride 1), a neuron at depth 1 sees a window of inputs: .
After a second conv with kernel (stride 1), each output sees neurons at depth 1, each of which already covered inputs — but adjacent depth-1 neurons share all but one input. Counting carefully, the depth-2 receptive field is . The recursion in general is
The product of upstream strides is the "jump" of layer : at depth , neighbouring neurons are input pixels apart, so adding a kernel of size adds such jumps to the receptive field.
5.2 Special cases
All stride 1, all kernels . The product of upstream strides is always 1, and
For : — the receptive field grows linearly in depth. To reach you need layers. To reach you need .
Stride 2 at every layer, all kernels . , and
For : — exponential growth in depth. To reach you need only layers.
The lesson is sharp: without striding or dilation, a stack of small kernels needs depth proportional to the desired receptive field.
5.3 Effective vs theoretical receptive field
The recursion above gives the theoretical receptive field — the set of input pixels that could influence a given output. But not all of them influence it equally. Luo et al. (2016)[4] showed that, even at full theoretical depth, the effective receptive field — the region whose pixels meaningfully contribute to the output — is dramatically smaller and approximately Gaussian, with a standard deviation that grows like instead of for stride-1 stacks. So the picture is even less favourable for CNNs than the count above suggests: doubling depth doesn't double the part of the input the network actually uses.[5]
6. The depth tax that motivates attention
Pull the threads together. To make every output position aware of every input position in a sequence of length using stride-1 convolutions of kernel :
For and : . For : . Even with stride or dilation tricks (WaveNet's dilated stack scales receptive field as , which is much better), the architectural fact remains: a conv layer mixes only inputs in a small fixed neighbourhood. Global mixing requires depth, parameters, and careful engineering of strides or dilations.
This is the gap attention closes. A single attention layer mixes every position with every position in one matrix product — in compute but in depth. Chapter 6 builds it from scratch. Session 4.3 collects the remaining structural reasons (positional flexibility, content-addressing) before we get there.
(a) Verify the recursion by hand for two layers with . Sketch which input pixels feed a single depth-2 neuron.
(b) A stride-1 stack of conv layers each with kernel 3 has receptive field . How many layers are needed to give every output a receptive field ? Compare with a dilated stack .
(c) Prove that the 2D map is separately equivariant under horizontal and vertical translations. Is it equivariant under rotations? Why or why not?
(d) Suppose you replace each kernel weight by a position-dependent weight (one kernel per output location, no sharing). Show that this layer is no longer translation-equivariant by exhibiting a specific and a specific where .
References
- [1]
Prince, S. J. D. (2023). Understanding Deep Learning, §10 (Convolutional Networks). MIT Press. — Receptive fields and equivariance treatment (4.2). udlbook.github.io
↩ - [2]
Hubel, D. H., & Wiesel, T. N. (1962). "Receptive fields, binocular interaction and functional architecture in the cat's visual cortex". Journal of Physiology, 160, 106–154. — Biological origin of local receptive fields (4.2).
↩ - [3]
Fukushima, K. (1980). "Neocognitron: A self-organizing neural network model for a mechanism of pattern recognition unaffected by shift in position". Biological Cybernetics, 36, 193–202. — First hierarchical model with weight sharing (4.2).
↩ - [4]
Luo, W., Li, Y., Urtasun, R., & Zemel, R. (2016). "Understanding the effective receptive field in deep convolutional neural networks". NeurIPS. arXiv:1701.04128 — Effective vs theoretical receptive field; Gaussian shape (4.2 §5.3).
↩ - [5]
He, K., Zhang, X., Ren, S., & Sun, J. (2016). "Deep residual learning for image recognition". CVPR. arXiv:1512.03385 — ResNet; deep stacks of small kernels (referenced in 4.2 §5).
↩ - [6]
van den Oord, A., Dieleman, S., Zen, H., et al. (2016). "WaveNet: A generative model for raw audio". arXiv:1609.03499 — Dilated 1D convolutions for sequences (4.2 Aside, 4.3 §2).
↩ - [7]
Shaw, P., Uszkoreit, J., & Vaswani, A. (2018). "Self-attention with relative position representations". NAACL. arXiv:1803.02155 — First relative positional encoding (6.6 §4.2).
↩ - [8]
Raffel, C., Shazeer, N., Roberts, A., et al. (2020). "Exploring the limits of transfer learning with a unified text-to-text transformer" (T5). JMLR. arXiv:1910.10683 — Bucketed relative positional bias (6.6 §4.2).
↩ - [9]
Wang, Q., Li, B., Xiao, T., et al. (2019). "Improving deep transformer with depth-scaled initialization and merged attention" (a.k.a. learning deep Transformers). arXiv:1908.11365 — Early analysis of post-LN instability; motivation for pre-LN (6.10 §4.2).
↩ - [10]
Gao, L., Biderman, S., Black, S., et al. (2020). "The Pile: An 800GB dataset of diverse text for language modeling". arXiv:2101.00027 — 22-source mixed corpus (7.1 §4.2).
↩