The Expressive Power of GNNs
The Weisfeiler–Leman test, GIN and going beyond it.
Two disjoint triangles and a hexagon: six nodes and six edges each, every node with exactly two neighbors. One graph is connected and the other is not; one contains triangles and the other does not. Yet no message-passing network, however large and however trained, maps them to different outputs. This lesson pins down exactly what message passing can tell apart, using a graph-isomorphism test from 1968, proves that sum aggregation reaches that limit while mean and max fall short, and climbs the hierarchy of more powerful and more expensive models beyond it.
What you’ll learn
- Run 1-WL color refinement, state what it can and cannot distinguish, and characterize it by tree homomorphism counts and counting logic.
- Prove that sum aggregation over bounded multisets is injective, conclude that GIN is as discriminative as 1-WL, and state exactly what mean and max aggregation lose.
- Explain the -WL hierarchy, the Cai–Fürer–Immerman construction and higher-order networks (-GNNs, invariant graph networks, PPGN), including the number of equivariant linear layers and their cost.
- Compare cheaper routes beyond 1-WL (subgraph GNNs, random features, substructure counts, Laplacian encodings, graph transformers) and the limits on counting substructures.
- Separate expressive power from generalization and from benchmark performance.
Color refinement
If 1-WL distinguishes two graphs, they are certainly not isomorphic; if it does not, they may or may not be. On typical graphs it is strong: for a uniformly random graph on nodes, the probability that two rounds already give every node its own color tends to 1 as grows (Babai, Erdős & Selkow, 1980), and then the graph is identified. Its failures are structured. Every node of a -regular graph sees its own color and neighbors of that same color, round after round, so 1-WL cannot distinguish any two -regular graphs with the same number of nodes.
Count the homomorphisms from a tree with nodes into a -regular graph with nodes. Map one node of anywhere ( choices); every further node, reached from its parent, must go to one of the neighbors of the parent's image:
The count depends only on and , so all -regular graphs on nodes agree on every tree: the regular-graph failure again, now explained. For the hexagon and the two triangles (, ), the path on 3 nodes has homomorphisms into each:
A cycle is not a tree, and here its counts differ: the triangle maps into each triangle in ways and not at all into the bipartite hexagon. Message passing is bounded by 1-WL, so it sees a graph only through its tree counts; information that only cycles carry, such as how many triangles a regular graph has, is out of its reach.
from collections import Counter
def wl_same(g1, g2, rounds=3):
"""1-WL on two graphs (adjacency lists) with one shared color table.
Returns, per round, whether the two color histograms are equal."""
colors, table, same = [[0] * len(g1), [0] * len(g2)], {}, []
for _ in range(rounds):
colors = [[table.setdefault((col[v], tuple(sorted(col[u] for u in adj[v]))), len(table))
for v in range(len(adj))] for adj, col in zip((g1, g2), colors)]
same.append(Counter(colors[0]) == Counter(colors[1]))
return same
def adjacency(n, edges):
adj = [[] for _ in range(n)]
for u, v in edges:
adj[u].append(v)
adj[v].append(u)
return adj
hexagon = adjacency(6, [(i, (i + 1) % 6) for i in range(6)])
triangles = adjacency(6, [(0, 1), (1, 2), (2, 0), (3, 4), (4, 5), (5, 3)])
print(wl_same(hexagon, triangles)) # [True, True, True]: 1-WL never tells them apartThe shared table plays the role of the injective hash: a node's new color is the index of the pair (own color, sorted neighbor colors). The decalin pair of the widget also gives True at every round, while 2- and 3-methylpentane give [True, False, False].
Message passing is exactly as strong as 1-WL
Part (a) follows by induction over the layers: two nodes with the same WL color always hold the same vector, because they start alike and receive equal multisets of neighbor vectors. Part (b) needs injective functions of multisets, and it is not obvious that a neural network can supply one with a simple sum.
The feature values are countable, so number them with an injective , and let every neighborhood multiset have fewer than elements. Map each value to a power of :
The counts are the base- digits of the sum, so the sum determines the multiset. Any function of the multiset is then for some , which an MLP can approximate:
The update also needs the node's own vector. Summing over would confuse a node of color with one neighbor of color and a node of color with one neighbor of color . Weighting the center by separates them: for infinitely many , every irrational one included, is injective on pairs . One MLP then models and together:
This is the graph isomorphism network (GIN). With sum readouts of every layer, concatenated, it is as discriminative as 1-WL. In Xu et al.'s experiments a fixed fitted the training data as well as a learned .
Encode atoms by with , , , for neighborhoods of fewer than 10 atoms. What is over a carbon atom's neighbors C, C and O?
Show the answer
0.201
. Read the decimal digits: 2 carbons, 0 nitrogens, 1 oxygen, so no two different neighborhoods can collide. Trained networks do not use this construction, which needs unbounded precision as the alphabet grows; it shows that a sum can be injective, whereas no choice of makes a mean or a max injective, since and always look the same to both.
Mean and max aggregation are permutation-invariant but not injective, and Xu et al. characterized exactly what they keep. A mean determines a multiset's distribution, the proportions of its elements: and always collide. A max determines only its underlying set: and collide. Even a sum fails if the map applied before it is a single layer without bias instead of an MLP: some pairs of distinct multisets give equal sums for every .
Climbing the hierarchy
To see more than 1-WL, color more than single nodes. The -dimensional test colors -tuples of nodes. Two tuples start with the same color when the subgraphs they induce are isomorphic with matching positions, and each round recolors a tuple by its own color together with, for every node , the colors of the tuples obtained by putting in position . Two versions exist: the folklore test -FWL groups these colors per node , the oblivious -WL treats them separately. For , -FWL is exactly as strong as -WL, and 2-WL is no stronger than 1-WL; "3-WL" in GNN papers therefore usually means 2-FWL.
Neural networks follow the same ladder. -GNNs (Morris et al., 2019) pass messages between -element subsets of nodes, mirroring a set-based -WL, and stack 1-, 2- and 3-dimensional layers hierarchically. Invariant graph networks (Maron, Ben-Hamu, Shamir & Lipman, 2019) act on the whole adjacency tensor, or on higher-order tensors, alternating linear layers that commute with relabeling and pointwise nonlinearities. How many such linear layers are there?
A linear map on matrices, , commutes with relabeling, for every permutation matrix , exactly when its coefficient tensor is unchanged by relabeling all four indices at once:
So is constant on each orbit of index tuples, and an orbit is fixed by which of the four indices are equal: an equality pattern, that is, a partition of . For every pattern occurs, and the indicator tensors of the patterns form a basis. Maps from order- to order- tensors have one basis element per partition of indices, once :
For sets (), the two patterns and give back Deep Sets' layer . For graphs () the 15 basis maps include the identity, the transpose, the diagonal, row and column sums broadcast along rows or columns, and the total sum broadcast everywhere; invariant readouts of a matrix () are spanned by maps, the trace and the sum of all entries.
With linear layers of order and pointwise nonlinearities, these networks separate exactly the graphs that oblivious -WL separates (at least these: Maron, Ben-Hamu, Serviansky & Lipman, 2019; at most these: Geerts, 2020), so order 2 is no stronger than message passing. One nonlinear operation changes that. PPGN (Maron, Ben-Hamu, Serviansky & Lipman, 2019) interleaves MLPs on the feature channels with matrix products of feature matrices, which mirror the update of 2-FWL, and reaches 2-FWL ("3-WL") power at time and memory per layer: provably beyond message passing, and costly on large graphs.
Cheaper ways past 1-WL
Cubic cost is out of reach for graphs with millions of nodes, so most practical models keep message passing and add one targeted signal that 1-WL lacks:
| Approach | What is added | What it buys | Cost |
|---|---|---|---|
| Subgraph GNNs: ESAN (Bevilacqua et al., 2022) | a shared GNN on a bag of subgraphs (each node or edge deleted, or ego-networks), aggregated equivariantly | strictly beyond 1-WL: deleting a node of the hexagon leaves a 5-node path, of the triangles an edge plus a triangle, which 1-WL separates in two rounds; node-based variants are at most as powerful as 2-FWL (Frasca et al., 2022) | about times one GNN, or sampled subgraphs |
| Random node features (Sato, Yamada & Kashima, 2021; Abboud, Ceylan, Grohe & Lukasiewicz, 2021) | random numbers appended to each node's input | universal approximation of invariant functions on graphs of a fixed size, with high probability; invariance holds only in expectation | none at run time; training must learn to ignore the noise |
| Substructure counts: GSN (Bouritsas, Frasca, Zafeiriou & Bronstein, 2023) | for each node, counts of the small patterns it belongs to (cycles, cliques), by role | beyond 1-WL for suitable patterns: one triangle per node in the triangles, none in the hexagon | pattern counting, polynomial for fixed small patterns |
| Laplacian eigenvectors (Dwivedi et al., 2020) | the first eigenvectors of the graph Laplacian as node features | global structure: the hexagon's spectrum differs from the triangles' ; eigenvector signs (and bases of repeated eigenvalues) are arbitrary, so training flips signs at random or uses sign-invariant networks (Lim et al., 2022) | an eigendecomposition: dense, less for a few eigenvectors of a sparse graph |
| Graph transformers: Graphormer (Ying et al., 2021), GraphGPS (Rampášek et al., 2022) | attention between all pairs, biased by shortest-path distance and fed degree embeddings (Graphormer); message passing plus global attention plus positional encodings (GPS) | distances separate the hexagon, with pairs 3 apart, from the triangles, with pairs not connected at all | attention, or with linear attention in GPS |
Graph theory offers other yardsticks. Zhang, Luo, Wang & He (2023) asked whether GNNs detect cut vertices and bridges, which linear-time algorithms find. Most existing architectures provably cannot; of those they examined, only the subgraph approach could. Their generalized distance WL adds distances to every aggregation: shortest-path distances handle bridges but not cut vertices, resistance distances handle cut vertices, using both handles every biconnectivity property they studied, and 2-FWL is at least as strong as either variant.
Which change lets a message-passing network separate the hexagon from the two triangles?
- Doubling the number of layers
- Replacing mean by max aggregation
- Adding each node's number of triangles as an input feature
- Randomly dropping edges during training
Show the answer
C. Adding each node's number of triangles as an input feature
The triangle count is 0 at every node of the hexagon and 1 at every node of the triangles, so the first round already sees the difference: the idea behind substructure-count features. The other changes leave the network inside the WL bound, which maps the two graphs alike.
Expressivity is not the whole story
Separating graphs and approximating functions on them are two views of one property: a model class separates every pair of non-isomorphic graphs exactly when it can approximate every continuous permutation-invariant function on graphs (Chen, Villar, Chen & Bruna, 2019). The WL hierarchy therefore also ranks which functions models can represent in principle. It says nothing about which functions they learn from finite data, and there capacity cuts both ways: Morris, Geerts, Tönshoff & Grohe (2023) bound a GNN's VC dimension by the number of colors 1-WL produces and, for graphs of bounded size, tie it tightly to the number of graphs 1-WL can tell apart. More discrimination can mean more data needed.
The experimental record shows the same tension. In Xu et al.'s benchmarks, GIN fitted the training sets far better than mean and max variants, but its test accuracy was often close to GCN's: 76.2% against 76.0% on PROTEINS and 80.2% against 79.0% on COLLAB. Higher-order models and graph transformers report gains where rings and distances matter, as in molecules, but careful re-evaluations have also found well-tuned message-passing baselines closing much of a reported gap (Oversmoothing & Oversquashing describes one such case).
Key takeaways
- 1-WL color refinement identifies almost all graphs but no pair of regular graphs of equal size and degree. It is equivalent to equal tree homomorphism counts and to the counting logic , and message passing can distinguish at most what it distinguishes.
- Sum aggregation over bounded multisets of countable features is injective ( turns counts into digits), so GIN, , matches 1-WL; a mean keeps only proportions and a max only the set of values.
- The -WL hierarchy is strict at every level (Cai–Fürer–Immerman) and -FWL costs time; invariant graph networks have equivariant linear maps between order- and order- tensors, and PPGN reaches 2-FWL with matrix products in .
- Cheaper routes past 1-WL add a specific signal: subgraphs, random node features, substructure counts, Laplacian eigenvectors or distance-aware attention. Plain message passing cannot induced-count any connected pattern with 3 or more nodes.
- Expressive power is not generalization: separating more graphs raises the VC dimension, and benchmark gains are often smaller than the theory suggests.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Two non-isomorphic 4-regular graphs have 10 nodes each and no node features. What do 1-WL and a GIN do with them?
- 1-WL separates them after one round, because their edge sets differ
- 1-WL keeps identical histograms forever, so no message-passing GNN, GIN included, maps them to different embeddings
- 1-WL fails, but a GIN trained long enough separates them
- 1-WL separates them because their triangle counts differ
Show the answer
B. 1-WL keeps identical histograms forever, so no message-passing GNN, GIN included, maps them to different embeddings
Every node starts gray and sees four gray neighbors, so every round gives all nodes of both graphs one common color. By the WL bound no message-passing network does better. Separating them needs other information: substructure counts, positional encodings or higher-order layers.
Which two neighborhoods can a mean aggregator never tell apart, whatever function it averages?
- and
- and
- and
- and
Show the answer
D. and
Both have the same distribution, half and half , so for every . A mean keeps proportions and forgets the count; a sum keeps both.
What did Cai, Fürer & Immerman (1992) prove about the Weisfeiler–Leman hierarchy?
- For every there are non-isomorphic graphs with nodes that -FWL cannot distinguish, so no fixed dimension identifies all graphs
- 3-FWL identifies every graph
- 1-WL and 2-FWL have the same power
- -FWL runs in linear time for every fixed
Show the answer
A. For every there are non-isomorphic graphs with nodes that -FWL cannot distinguish, so no fixed dimension identifies all graphs
Their construction shows the hierarchy is strict and never ends: each dimension has its own blind spots. Many classes are still identified at a small dimension, planar graphs at 3, but not all graphs.
What does the VC-dimension analysis of Morris, Geerts, Tönshoff & Grohe (2023) imply about making a GNN more expressive?
- Nothing: expressive power and generalization are unrelated
- More expressive GNNs always generalize better
- Capacity grows with discrimination: for graphs of bounded size the VC dimension is tightly tied to the number of graphs 1-WL can tell apart, so separating more graphs can demand more training data
- The VC dimension depends only on the number of layers
Show the answer
C. Capacity grows with discrimination: for graphs of bounded size the VC dimension is tightly tied to the number of graphs 1-WL can tell apart, so separating more graphs can demand more training data
Separating more graphs means a larger hypothesis class. They bound the VC dimension by the number of colors 1-WL produces and, for bounded graph order, tie it tightly to the number of 1-WL-distinguishable graphs; without a bound on the order, the bit length of the weights controls it. Expressivity is capacity, not a guarantee of low test error.
Further reading
- K. Xu, W. Hu, J. Leskovec & S. Jegelka, "How powerful are graph neural networks?," ICLR (2019).
- C. Morris, M. Ritzert, M. Fey, W. L. Hamilton, J. E. Lenssen, G. Rattan & M. Grohe, "Weisfeiler and Leman go neural: higher-order graph neural networks," AAAI (2019).
- H. Maron, H. Ben-Hamu, H. Serviansky & Y. Lipman, "Provably powerful graph networks," NeurIPS (2019).
- Z. Chen, L. Chen, S. Villar & J. Bruna, "Can graph neural networks count substructures?," NeurIPS (2020).
- C. Morris, Y. Lipman, H. Maron, B. Rieck, N. M. Kriege, M. Grohe, M. Fey & K. Borgwardt, "Weisfeiler and Leman go machine learning: the story so far," Journal of Machine Learning Research 24 (2023).