Simple Algorithm
Machine Learning · Convergence · 28 min

Architectures as Inductive Bias

Invariance and equivariance: why CNNs, GNNs and transformers look the way they do.

A convolutional network does not have to learn that a cat in the corner is still a cat, and a graph network does not have to learn that renumbering the atoms of a molecule changes nothing. Building a symmetry into an architecture removes it from what must be learned. This lesson makes "built-in symmetry" precise with groups, derives the equivariant layers for grids and sets, proves the limit of message passing on graphs, computes the statistical gain from invariance exactly in a linear model, and weighs all of it against the bitter lesson.

What you’ll learn

  • Define group actions, invariance and equivariance; prove that group convolution is equivariant and that equivariant layers followed by invariant pooling give an invariant network.
  • Derive every permutation-equivariant linear map on sets, λI+γ11⊤\lambda I+\gamma\mathbf 1\mathbf 1^\top, and state the Deep Sets theorem with its limits for continuous maps.
  • Prove that message-passing networks cannot separate graphs that the 1-dimensional Weisfeiler–Lehman test cannot, and exhibit such a pair.
  • State the strict generalization gain of invariant linear models, and weigh built-in symmetry against learning it from data at scale.

Symmetry, made precise

A group GG acts on the inputs when each g∈Gg\in G gives a map x↦g⋅x\mathbf x\mapsto g\cdot\mathbf x, the identity does nothing, and (gh)⋅x=g⋅(h⋅x)(gh)\cdot\mathbf x=g\cdot(h\cdot\mathbf x). Examples: circular translations of an image, rotations by multiples of 90°90°, permutations of the nn elements of a set or of the nodes of a graph. A function is invariant if f(g⋅x)=f(x)f(g\cdot\mathbf x)=f(\mathbf x) and equivariant if f(g⋅x)=g⋅f(x)f(g\cdot\mathbf x)=g\cdot f(\mathbf x), where GG may act differently on the output. Class labels should be invariant; feature maps, segmentation masks and per-node predictions should be equivariant.

Two one-line facts organize architecture design. If f1,…,fLf_1,\dots,f_L are equivariant, so is fL∘⋯∘f1f_L\circ\dots\circ f_1, since each layer passes gg through to the next. And an invariant map applied after equivariant ones gives an invariant network: P(F(g⋅x))=P(g⋅F(x))=P(F(x))P(F(g\cdot\mathbf x))=P(g\cdot F(\mathbf x))=P(F(\mathbf x)). The "geometric deep learning" blueprint of Bronstein, Bruna, Cohen & Veličković (2021) is exactly this: equivariant layers, local pooling, and a final invariant pooling.

DerivationGroup convolution is equivariant (Cohen & Welling, 2016)
  1. [f⋆ψ](g)=∑h∈Gf(h) ψ(g−1h)[f\star\psi](g)=\sum_{h\in G}f(h)\,\psi(g^{-1}h)

    For a finite group GG, represent a feature map as a function f:G→Rf:G\to\R and let GG act by left translation, (Luf)(h)=f(u−1h)(L_uf)(h)=f(u^{-1}h). Group cross-correlation with a filter ψ\psi is

  2. [(Luf)⋆ψ](g)=∑hf(u−1h) ψ(g−1h)=∑h′f(h′) ψ((u−1g)−1h′)=[f⋆ψ](u−1g)[(L_uf)\star\psi](g)=\sum_{h}f(u^{-1}h)\,\psi(g^{-1}h)=\sum_{h'}f(h')\,\psi\big((u^{-1}g)^{-1}h'\big)=[f\star\psi](u^{-1}g)

    Translate the input by uu and substitute h=uh′h=uh', which runs over all of GG as h′h' does:

  3. (Luf)⋆ψ=Lu(f⋆ψ)for all u∈G(L_uf)\star\psi=L_u(f\star\psi)\qquad\text{for all }u\in G

    The right side is [Lu(f⋆ψ)](g)[L_u(f\star\psi)](g): filtering commutes with the group action. For GG the translations of a grid this is the ordinary convolutional layer; for translations plus rotations by 90°90° (the group p4), the same filter is applied in all four orientations, a higher degree of weight sharing at no extra parameter cost.

The converse also holds in great generality: Kondor & Trivedi (2018) showed that, under natural conditions, a feed-forward layer is equivariant to the action of a compact group only if it has this generalized convolutional form. Convolution is not one architecture among many; it is what equivariance forces.

Sets: equivariant layers and Deep Sets

DerivationProof
  1. Lπ(i)π(j)=Lijfor all i,j and all permutations πL_{\pi(i)\pi(j)}=L_{ij}\qquad\text{for all }i,j\text{ and all permutations }\pi

    Equivariance for every PP means PLP⊤=LPLP^\top=L, so the entries are unchanged when a permutation π\pi is applied to both indices:

  2. L=λI+γ 11⊤L=\lambda I+\gamma\,\mathbf 1\mathbf 1^\top

    A permutation can send any diagonal position (i,i)(i,i) to any other (k,k)(k,k), so all diagonal entries are equal; it can send any off-diagonal pair (i,j)(i,j), i≠ji\ne j, to any other (k,l)(k,l), k≠lk\ne l, so all off-diagonal entries are equal too. Call them λ+γ\lambda+\gamma and γ\gamma:

  3. Conversely P1=1P\mathbf 1=\mathbf 1, so P(λI+γ11⊤)P⊤=λI+γ11⊤P(\lambda I+\gamma\mathbf 1\mathbf 1^\top)P^\top=\lambda I+\gamma\mathbf 1\mathbf 1^\top. With cc channels per element the layer becomes X↦XΛ+11⊤XΓX\mapsto X\Lambda+\mathbf 1\mathbf 1^\top X\Gamma for c×cc\times c matrices Λ,Γ\Lambda,\Gamma: 2c22c^2 parameters whatever the set size, instead of (nc)2(nc)^2 for a dense layer.

The same counting extends to graphs. Maron, Ben-Hamu, Shamir & Lipman (2019) characterized all permutation-equivariant linear layers on kk-th order tensors, such as adjacency matrices (k=2k=2): their dimension is a Bell number, the number of ways to partition a set, and once a graph has at least 2k2k nodes it does not depend on how many it has.

Predict before you look

How many independent parameters does a permutation-equivariant linear layer from Rn×n\R^{n\times n} to Rn×n\R^{n\times n} (one channel in and out, edge-valued graphs with n≥4n\ge4 nodes) have? It is the number of ways to partition the four indices of the weight tensor Wij,klW_{ij,kl} into groups of equal indices.

Show the answer

15

The Bell number b(4)=15b(4)=15. Each partition of {i,j,k,l}\{i,j,k,l\} gives one basis map: the identity, the transpose, broadcasting row sums, column sums, the diagonal, the total sum, and so on. For invariant maps to R\R the count is b(2)=2b(2)=2: the trace and the total sum. For sets (k=1k=1) the equivariant count is b(2)=2b(2)=2, the λ\lambda and γ\gamma above.

That construction is wildly discontinuous. Wagstaff, Fuchs, Engelcke, Posner & Osborne (2019) proved that with continuous ϕ\phi and ρ\rho, as neural networks provide, representing every continuous permutation-invariant function on sets of up to NN real numbers needs a latent dimension of at least NN. Sum-decomposition is universal, but the width of the sum must grow with the set size.

Self-attention is the other standard permutation-equivariant layer on sets: Attn(PX)=P Attn(X)\mathrm{Attn}(PX)=P\,\mathrm{Attn}(X), as derived in Representations, Transfer & Inductive Bias. Where λI+γ11⊤\lambda I+\gamma\mathbf 1\mathbf 1^\top lets each element see the others only through their plain sum, attention weights them by content, so a transformer without positional encodings is a set processor. Positional encodings (Vaswani et al., 2017), or a causal mask, break the symmetry on purpose when order carries information.

Graphs: message passing and the Weisfeiler–Lehman limit

A message-passing network (GNN; Gilmer, Schoenholz, Riley, Vinyals & Dahl, 2017) updates each node from its own state and the multiset of its neighbors' states, then pools all nodes:

hv(t+1)=Ut(hv(t), ∑u∈N(v)Mt(hv(t),hu(t),euv)),y^=R({ ⁣{hv(T):v∈V} ⁣}).\mathbf h_v^{(t+1)}=U_t\Big(\mathbf h_v^{(t)},\ \sum_{u\in N(v)}M_t\big(\mathbf h_v^{(t)},\mathbf h_u^{(t)},\mathbf e_{uv}\big)\Big),\qquad\hat y=R\big(\{\!\{\mathbf h_v^{(T)}:v\in V\}\!\}\big).

Renumbering the nodes permutes the states, so every layer is equivariant and the readout invariant. The classical 1-dimensional Weisfeiler–Lehman test (color refinement) does the same thing with colors instead of vectors: start with node labels, and repeatedly recolor each node by an injective hash of its color and the multiset of its neighbors' colors. Two graphs whose color histograms ever differ are certainly not isomorphic.

DerivationProof of the limit
  1. cu(t)=cv(t)⟹hu(t)=hv(t)c_u^{(t)}=c_v^{(t)}\quad\Longrightarrow\quad\mathbf h_u^{(t)}=\mathbf h_v^{(t)}

    Run WL and the network side by side on both graphs, with initial features determined by the node labels. Claim: at every round, two nodes (in either graph) with the same WL color have the same state. At t=0t=0 this holds because both are functions of the label.

  2. cu(t+1)=cv(t+1) ⟹ hu(t)=hv(t) and { ⁣{hu′(t)} ⁣}u′∈N(u)={ ⁣{hv′(t)} ⁣}v′∈N(v) ⟹ hu(t+1)=hv(t+1)c_u^{(t+1)}=c_v^{(t+1)}\ \Longrightarrow\ \mathbf h_u^{(t)}=\mathbf h_v^{(t)}\ \text{and}\ \{\!\{\mathbf h_{u'}^{(t)}\}\!\}_{u'\in N(u)}=\{\!\{\mathbf h_{v'}^{(t)}\}\!\}_{v'\in N(v)}\ \Longrightarrow\ \mathbf h_u^{(t+1)}=\mathbf h_v^{(t+1)}

    Inductive step: equal colors at round t+1t+1 mean equal colors at round tt and equal multisets of neighbor colors (the hash is injective). By the induction hypothesis the states and the multisets of neighbor states are then equal too, and the update depends on nothing else:

  3. So each state is a function of the WL color, and the multiset of states of a graph is a function of its color histogram. Equal histograms give equal readouts.

A concrete blind spot: two disjoint triangles versus a single 6-cycle. Every node in both graphs has exactly two neighbors, so with uniform initial labels color refinement never splits any color, and the histograms agree forever. No message-passing network can tell these graphs apart, although only one contains a triangle and only one is connected. Aggregation matters as well: a mean cannot distinguish the neighborhood {a,b}\{a,b\} from {a,a,b,b}\{a,a,b,b\}, and a max cannot count, which is why GIN sums. Higher-order networks that pass messages between tuples of nodes go beyond 1-WL, at a higher cost (Morris et al., 2019).

Check your understanding

Which pair of graphs (unlabeled nodes) is guaranteed to be mapped to the same embedding by every message-passing network?

  1. A path on 4 nodes and a star on 4 nodes
  2. Two disjoint triangles and a 6-cycle
  3. A triangle and a path on 3 nodes
  4. Any two graphs with the same number of edges
Show the answer

B. Two disjoint triangles and a 6-cycle

Both graphs are 2-regular on 6 nodes, so color refinement assigns every node the same color at every round; by the WL limit no message-passing network separates them. In the other pairs the degree sequences already differ after one round.

What symmetry buys, and the bitter lesson

DerivationWhy the gain is dim A over n − d − 1
  1. E[R(w^)]−σ2=σX2 E∥w^−θ∥2=σ2 dn−d−1\E\big[R(\hat{\mathbf w})\big]-\sigma^2=\sigma_X^2\,\E\norm{\hat{\mathbf w}-\boldsymbol\theta}^2=\sigma^2\,\frac{d}{n-d-1}

    The least-squares error is pure noise, w^−θ=(X⊤X)−1X⊤ξ\hat{\mathbf w}-\boldsymbol\theta=(X^\top X)^{-1}X^\top\boldsymbol\xi. For a Gaussian design, E(X⊤X)−1=I/(σX2(n−d−1))\E(X^\top X)^{-1}=I/\big(\sigma_X^2(n-d-1)\big), so each of the dd directions contributes the same excess risk:

  2. E[R(wˉ)]−σ2=σ2 dim⁡Sn−d−1\E\big[R(\bar{\mathbf w})\big]-\sigma^2=\sigma^2\,\frac{\dim S}{n-d-1}

    The target is invariant, so PSθ=θP_S\boldsymbol\theta=\boldsymbol\theta and the projection keeps only the error inside SS: wˉ−θ=PS(w^−θ)\bar{\mathbf w}-\boldsymbol\theta=P_S(\hat{\mathbf w}-\boldsymbol\theta). No bias is added, and only dim⁡S\dim S directions of noise remain:

  3. E[R(w^)−R(wˉ)]=σ2 dim⁡An−d−1\E\big[R(\hat{\mathbf w})-R(\bar{\mathbf w})\big]=\sigma^2\,\frac{\dim A}{n-d-1}

    Subtract, using d=dim⁡S+dim⁡Ad=\dim S+\dim A. The symmetry acts like a reduction of the dimension from dd to dim⁡S\dim S, and the gain is larger the more of the space the symmetry rules out:

Predict before you look

Take d=10d=10 features and the target invariant under all permutations of the coordinates, so the invariant predictors are multiples of 1\mathbf 1 (dim⁡S=1\dim S=1, dim⁡A=9\dim A=9). With n=100n=100 examples and noise variance σ2=1\sigma^2=1, what is the expected gain in test error from averaging the least-squares fit over the group?

Show the answer

0.101

9/(100−10−1)=9/89≈0.1019/(100-10-1)=9/89\approx0.101. Least squares has excess risk 10/89≈0.11210/89\approx0.112, the symmetrized estimator 1/89≈0.0111/89\approx0.011: a tenfold reduction, because nine of the ten noisy directions are eliminated. Elesedy & Zaidi also show the gap diverges near the interpolation threshold n≈dn\approx d, echoing double descent.

Building a symmetry in enforces it exactly and for free; augmentation teaches it only approximately, through data and compute (Regularizing Neural Networks proves that augmenting with an exact symmetry leaves the expected loss unchanged and lowers the variance of its estimate). But a built-in symmetry must be right, and it must be worth its constraints.

Sutton's (2019) essay "The Bitter Lesson" draws the opposite moral from seventy years of AI research: general methods that leverage computation, above all search and learning, have ultimately proved the most effective, by a large margin, while building in human knowledge helps in the short term and then plateaus. Vision transformers are a case in point. Dosovitskiy et al. (2021) found that, trained on ImageNet alone without strong regularization, a pure transformer on image patches trailed ResNets of comparable size by a few percentage points, since it lacks their translation equivariance and locality; pretrained on 14 to 300 million images it attained excellent results, and in their words "large scale training trumps inductive bias". The two readings are compatible: built-in symmetry buys sample efficiency, which matters most where data are scarce and the symmetry is exact (molecules, physical systems, point clouds), and matters less where data are abundant.

Key takeaways

  • Equivariant layers compose, and an invariant pooling after them gives an invariant network. Group convolution commutes with the group action, and for compact groups (under natural conditions) equivariance forces a convolutional form.
  • Permutation-equivariant linear maps on sets are exactly λI+γ11⊤\lambda I+\gamma\mathbf 1\mathbf 1^\top; on edge-valued graphs they form a 15-dimensional space. Invariant set functions are ρ(∑ϕ(x))\rho(\sum\phi(x)), but with continuous maps the latent dimension must reach the set size.
  • Message-passing networks are at most as powerful as 1-WL color refinement, so they cannot separate, for example, two triangles from a 6-cycle; sum aggregation (GIN) attains the bound.
  • For invariant linear targets, symmetrizing least squares gains exactly σ2dim⁡A/(n−d−1)\sigma^2\dim A/(n-d-1); built-in symmetry buys sample efficiency, which matters most when data are scarce, while at very large scale learning can recover much of it (the bitter lesson).

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A linear layer Rn→Rn\R^n\to\R^n (one channel, n≥2n\ge2) is required to be permutation-equivariant. How many free parameters remain?

  1. n2n^2
  2. nn
  3. 11
  4. 22
Show the answer

D. 22

Every such layer is λI+γ11⊤\lambda I+\gamma\mathbf 1\mathbf 1^\top: one weight for an element's own value, one for the sum over the set, independent of nn.

Question 2

A network stacks several translation-equivariant convolutional layers and ends with a global average over all spatial positions. What is true of its output?

  1. It is equivariant: a shifted input gives a shifted output
  2. It has no particular symmetry, because the layers are nonlinear
  3. It is invariant to cyclic shifts of the input, because equivariant layers followed by an invariant pooling give an invariant map
  4. It is invariant to rotations as well as translations
Show the answer

C. It is invariant to cyclic shifts of the input, because equivariant layers followed by an invariant pooling give an invariant map

Each layer passes the shift through, F(g⋅x)=g⋅F(x)F(g\cdot\mathbf x)=g\cdot F(\mathbf x), and averaging over all positions ignores where things are. For exact invariance the shifts must be cyclic (or the borders handled accordingly), and strides break exactness in real networks.

Question 3

Why does the Graph Isomorphism Network aggregate neighbors by a sum rather than a mean or a max?

  1. A sum is cheaper to compute
  2. Followed by a multilayer perceptron, a sum can be injective on multisets, which is needed to match the power of 1-WL; mean and max lose multiplicities
  3. A sum makes the network rotation-invariant
  4. A mean would break permutation equivariance
Show the answer

B. Followed by a multilayer perceptron, a sum can be injective on multisets, which is needed to match the power of 1-WL; mean and max lose multiplicities

To be as powerful as color refinement the aggregation must distinguish different multisets of neighbor states. A mean cannot tell {a,b}\{a,b\} from {a,a,b,b}\{a,a,b,b\} and a max cannot count; a sum of suitable features can be injective (for countable feature sets).

Question 4

In Elesedy & Zaidi's linear model, what determines how much averaging the least-squares estimator over the symmetry group improves its expected test error?

  1. The noise variance times dim⁡A/(n−d−1)\dim A/(n-d-1), where AA is the complement of the invariant subspace
  2. The number of elements of the group
  3. Nothing: averaging only helps when the target is not invariant
  4. The squared norm of the true parameter θ\boldsymbol\theta
Show the answer

A. The noise variance times dim⁡A/(n−d−1)\dim A/(n-d-1), where AA is the complement of the invariant subspace

Projecting onto the invariant subspace removes the noise in the dim⁡A\dim A directions that the symmetry excludes, without adding bias since the target is invariant. Each removed direction is worth σ2/(n−d−1)\sigma^2/(n-d-1).

Further reading

  • T. Cohen & M. Welling, "Group equivariant convolutional networks," ICML (2016).
  • M. Zaheer, S. Kottur, S. Ravanbakhsh, B. Póczos, R. Salakhutdinov & A. Smola, "Deep sets," NeurIPS (2017).
  • K. Xu, W. Hu, J. Leskovec & S. Jegelka, "How powerful are graph neural networks?," ICLR (2019).
  • B. Elesedy & S. Zaidi, "Provably strict generalisation benefit for equivariant models," ICML (2021).
  • M. M. Bronstein, J. Bruna, T. Cohen & P. Veličković, "Geometric deep learning: grids, groups, graphs, geodesics, and gauges," arXiv:2104.13478 (2021).