AI / ML Theory
Chapter 4 · 22 min

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:

  1. Define translation equivariance.
  2. Prove that 1D and 2D convolutions are translation-equivariant, and identify weight sharing as the reason.
  3. Compute receptive fields exactly and see the "depth tax" that motivates attention.[1]

2. Equivariance vs invariance

Let ThT_h denote the translation operator that shifts an input by hh positions:

(Thx)[n]=x[n−h].(T_h x)[n] = x[n - h].

(For images, T(hy,hx)x[i,j]=x[i−hy, j−hx]T_{(h_y, h_x)} x[i, j] = x[i - h_y,\, j - h_x].)

A map ff is translation-equivariant if shifting the input shifts the output by the same amount:

 f(Thx)=Th f(x)for all x and all shifts h. \boxed{\ f(T_h x) = T_h\, f(x) \quad \text{for all } x \text{ and all shifts } h. \ }

It is translation-invariant if shifting the input doesn't change the output at all:

f(Thx)=f(x).f(T_h x) = f(x).

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 Cw(x)[i]=∑kw[k] x[i+k]C_w(x)[i] = \sum_k w[k]\, x[i + k] be 1D cross-correlation with kernel ww. Then Cw(Thx)=Th Cw(x)C_w(T_h x) = T_h\, C_w(x).

Proof. Compute the left side directly:

Cw(Thx)[i]=∑kw[k] (Thx)[i+k]=∑kw[k] x[(i+k)−h]=∑kw[k] x[(i−h)+k].C_w(T_h x)[i] = \sum_k w[k]\, (T_h x)[i + k] = \sum_k w[k]\, x[(i + k) - h] = \sum_k w[k]\, x[(i - h) + k].

The last expression is Cw(x)[i−h]C_w(x)[i - h], which is Th Cw(x)[i]T_h\, C_w(x)[i]. So

Cw(Thx)[i]=Th Cw(x)[i]for every i,C_w(T_h x)[i] = T_h\, C_w(x)[i] \quad \text{for every } i,

and equivariance is established. ■\blacksquare

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 ii.

3.1 Why a generic linear map fails

A generic linear map L:RN→RNL : \mathbb{R}^N \to \mathbb{R}^N has a matrix L[i,j]L[i, j] with no constraints. Equivariance would require L[i,j]=L[i−h,j−h]L[i, j] = L[i - h, j - h] for all i,j,hi, j, h — 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 Zd\mathbb{Z}^d 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 w[k]w[k] depends only on the offset kk, not on the output position ii. The same numeric kernel is used at every output location.

This is called weight sharing, and it is the structural reason convolutions have O(CinCoutKhKw)O(C_\text{in} C_\text{out} K_h K_w) parameters independent of H×WH \times W. Each entry of WW is a parameter re-used at Hout⋅WoutH_\text{out} \cdot W_\text{out} 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 w[k]w[k] 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 LL?

5.1 Definition and recursion

Index layers 1,2,…,L1, 2, \dots, L. Layer ℓ\ell uses a kernel of size KℓK_\ell and stride sℓs_\ell. Define rℓr_\ell as the receptive field of a single neuron at depth ℓ\ell, measured in input pixels.

At the input, r0=1r_0 = 1 (the identity).

After one conv with kernel K1K_1 (stride 1), a neuron at depth 1 sees a window of K1K_1 inputs: r1=K1r_1 = K_1.

After a second conv with kernel K2K_2 (stride 1), each output sees K2K_2 neurons at depth 1, each of which already covered K1K_1 inputs — but adjacent depth-1 neurons share all but one input. Counting carefully, the depth-2 receptive field is r2=K1+(K2−1)r_2 = K_1 + (K_2 - 1). The recursion in general is

 rℓ=rℓ−1+(Kℓ−1)∏j=1ℓ−1sj. \boxed{\ r_\ell = r_{\ell - 1} + (K_\ell - 1) \prod_{j = 1}^{\ell - 1} s_j. \ }

The product of upstream strides is the "jump" of layer ℓ\ell: at depth ℓ\ell, neighbouring neurons are ∏j<ℓsj\prod_{j < \ell} s_j input pixels apart, so adding a kernel of size KℓK_\ell adds (Kℓ−1)(K_\ell - 1) such jumps to the receptive field.

5.2 Special cases

All stride 1, all kernels KK. The product of upstream strides is always 1, and

rL=1+L(K−1).r_L = 1 + L (K - 1).

For K=3K = 3: rL=1+2Lr_L = 1 + 2L — the receptive field grows linearly in depth. To reach r=1024r = 1024 you need L=512L = 512 layers. To reach r=64r = 64 you need L=32L = 32.

Stride 2 at every layer, all kernels KK. ∏j<ℓsj=2ℓ−1\prod_{j < \ell} s_j = 2^{\ell - 1}, and

rL=1+(K−1)(2L−1).r_L = 1 + (K - 1)(2^L - 1).

For K=3K = 3: rL=1+2(2L−1)=2L+1−1r_L = 1 + 2(2^L - 1) = 2^{L + 1} - 1 — exponential growth in depth. To reach r=1024r = 1024 you need only L≈9L \approx 9 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 L\sqrt{L} instead of LL 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 TT using stride-1 convolutions of kernel KK:

rL≥T  ⟺  L≥T−1K−1.r_L \ge T \quad \iff \quad L \ge \frac{T - 1}{K - 1}.

For T=1024T = 1024 and K=3K = 3: L≥512L \ge 512. For K=7K = 7: L≥171L \ge 171. Even with stride or dilation tricks (WaveNet's dilated stack scales receptive field as 2L2^L, 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 — O(T2)O(T^2) in compute but O(1)O(1) in depth. Chapter 6 builds it from scratch. Session 4.3 collects the remaining structural reasons (positional flexibility, content-addressing) before we get there.

Self-test

(a) Verify the recursion rℓ=rℓ−1+(Kℓ−1)∏j<ℓsjr_\ell = r_{\ell - 1} + (K_\ell - 1) \prod_{j < \ell} s_j by hand for two layers with K1=3,s1=2,K2=3,s2=1K_1 = 3, s_1 = 2, K_2 = 3, s_2 = 1. Sketch which input pixels feed a single depth-2 neuron.

(b) A stride-1 stack of LL conv layers each with kernel 3 has receptive field rL=1+2Lr_L = 1 + 2L. How many layers are needed to give every output a receptive field ≥4096\ge 4096? Compare with a dilated stack dℓ=2ℓ−1d_\ell = 2^{\ell - 1}.

(c) Prove that the 2D map z[i,j]=∑k,lw[k,l] x[i+k,j+l]z[i, j] = \sum_{k, l} w[k, l]\, x[i + k, j + l] is separately equivariant under horizontal and vertical translations. Is it equivariant under rotations? Why or why not?

(d) Suppose you replace each kernel weight w[k,l]w[k, l] by a position-dependent weight wij[k,l]w_{ij}[k, l] (one kernel per output location, no sharing). Show that this layer is no longer translation-equivariant by exhibiting a specific wijw_{ij} and a specific hh where f(Thx)≠Thf(x)f(T_h x) \neq T_h f(x).


References

  1. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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).

    ↩