CS224W

Lecture 6 · Thu 10/8 · slides PDF · lecture notes

Theory of GNNs — How Expressive Are They?

A message-passing GNN can only tell apart what its neighbourhood aggregation can tell apart; sum aggregation (GIN) reaches the ceiling, and that ceiling is the Weisfeiler–Lehman test.

25
sectionstick "got it" as you go
17
figuresredrawn from the slides
interactive figuresplay with the ideas
5
self-check questionsplus flashcards
19′
reading time4,200 words, walkthrough aside

Before you start: review of the earlier sessions

The thread so far. Sessions 3–5 built GNNs; session 6 asks what they can represent and answers with the WL test. Sessions 7 and 8 are two routes around the ceiling found here.

What this session takes from earlier ones

  • Lecture 3: the computation graph: here it becomes a rooted subtree
  • Lecture 4: the aggregators (mean, max, sum) whose power is compared
  • Lecture 5: self-supervised structural labels, which are what an expressive GNN must be able to compute

Those sessions in one minute each

Lecture 5 · GNN Augmentation and Training

Choose the computation graph deliberately (features, virtual nodes, sampling), pick the head that matches the task level, and split so that information from validation/test can never leak into training through message passing.

\[ \hat y_v=\mathbf{W}^{(H)}\mathbf{h}_v^{(L)},\qquad \hat y_{uv}=\mathbf{h}_u^{(L)\top}\mathbf{h}_v^{(L)},\qquad \hat y_G=\text{Pool}\big(\{\mathbf{h}_v^{(L)}:v\in G\}\big) \]

Lecture 3 · Graph Neural Networks

A GNN layer = for every node, combine its own vector with an order-free aggregate of its neighbours' vectors, using weights shared across all nodes; stacking K layers lets information travel K hops.

\[ H^{(k+1)}=\sigma\big(D^{-1}A\,H^{(k)}W_k^\top + H^{(k)}B_k^\top\big) \]

Rows of \(H\) are node embeddings; \(D^{-1}A\) averages over neighbours; \(W_k\) transforms the neighbourhood message; \(B_k\) transforms the node itself.

Lecture 4 · A General Perspective on GNNs

A GNN layer is "message, then order-free aggregation (including yourself)"; architectures differ in how neighbours are weighted, and depth must be matched to the receptive field you need because too many layers smooth everything into one vector.

\[ \alpha_{vu}=\frac{\exp(e_{vu})}{\sum_{k\in N(v)}\exp(e_{vk})},\qquad \mathbf{h}_v^{(l)}=\sigma\Big(\sum_{u\in N(v)}\alpha_{vu}\,\mathbf{W}^{(l)}\mathbf{h}_u^{(l-1)}\Big) \]

GCN is the special case \(\alpha_{vu}=1/|N(v)|\) (fixed); GAT learns \(e_{vu}=a(\mathbf{W}\mathbf{h}_u,\mathbf{W}\mathbf{h}_v)\).

Warm-up: answer these before you read on

When would you add a virtual node? from Lecture 5

When the graph is too sparse for messages to travel, e.g. long chains; the virtual node connects to everything, so any two nodes are two hops apart.

Why can a GNN embed a node it has never seen? from Lecture 3

Because the parameters are the shared weight matrices, not per-node vectors; a new node just needs its features and its neighbours to build its computation graph.

Where does GAT put its parameters that GCN does not have? from Lecture 4

In the attention mechanism: a learned function of the pair (node, neighbour) that produces the aggregation weights, instead of fixed degree-based weights.

Why can you not simply split nodes at random for link prediction? from Lecture 5

Edges used for message passing must not also be the edges you are predicting; otherwise the model sees the answer. Message, supervision, validation and test edges are kept apart.

More questions from every session you have reached, with spaced repetition: the cumulative review.

In short

We have many GNNs. Which is most powerful, and is there a limit? "Power" here means expressiveness: the ability to give different embeddings to nodes (or graphs) whose structures differ.

The key reduction: a GNN embeds a node by recursively aggregating over its rooted subtree (the computation graph). If every aggregation step is injective on the multiset of neighbour vectors, different subtrees get different embeddings — and that's the best any message-passing GNN can do.

Mean aggregation (GCN) can't tell \(\{a,b\}\) from \(\{a,a,b,b\}\); max (GraphSAGE-pool) can't tell \(\{a,b\}\) from \(\{a,a,b\}\). Sum of a suitable encoding can tell all multisets apart. Wrap it in MLPs and you get the Graph Isomorphism Network (GIN), which is exactly as powerful as the classical 1-WL colour-refinement test — strong on most real graphs, but blind to some structures like cycle lengths.

The picture: three aggregators, three multisets

Why mean and max fail and sum succeeds multiset Amultiset Bmeanmaxsum same ✗ 1 same ✗differ ✓ same ✗ 2 differ ✓differ ✓ Σ one-hot = counts 3 sum (multiset) > mean (distribution) > max (set) what each aggregator can "see" of the neighbour multiset 4

How to read it (hover a step; colours = node features)

  1. Mean fails when the colour proportions are equal: \(\{o,b\}\) and \(\{o,o,b,b\}\) (o = orange, b = blue) both average to \((0.5,0.5)\). Max also fails here.
  2. Max fails when the set of distinct colours is equal: \(\{o,b\}\) and \(\{o,o,b\}\) both have element-wise max \((1,1)\). Mean succeeds here (1/2 vs 2/3).
  3. Sum of one-hot encodings returns the colour counts — it remembers the whole multiset.
  4. Ranking by discriminative power: sum sees the multiset, mean sees only the distribution, max sees only the underlying set.

1 · What a GNN can see: rooted subtrees

We focus on message-passing GNNs (message + aggregation). Use colours for features; in the running example all nodes share one feature. Then the question is purely structural: can node embeddings distinguish different local neighbourhood structures?

  • Nodes 1 and 5 differ — different degrees.
  • Nodes 1 and 4 have the same degree 2, but their neighbours' degrees differ (2,3 vs 1,3) — so they differ at depth 2.
  • Nodes 1 and 2 are symmetric in the graph — any GNN must give them the same embedding.
  • Nodes 1 and 2 have identical computation graphs, hence the same embedding. slide 21 ↗

A GNN computes \(\mathbf{h}_v\) through the computation graph, which equals the rooted subtree obtained by recursively unfolding neighbours. The GNN never sees node IDs, only features. So: same rooted subtree + same features ⇒ same embedding, no matter which GNN.

Computational graphs = rooted subtree structures. slide 23 ↗

Subtrees can be characterised recursively from the leaves up: "a root with (2 neighbours, 3 neighbours)" ≠ "a root with (1 neighbour, 3 neighbours)". If every aggregation step retains full information about its neighbour multiset, then different subtrees get different embeddings. That is: the most expressive GNN uses an injective neighbour aggregation at every step.

Injective aggregation at every level distinguishes different subtrees. slide 28 ↗

2 · Analysing aggregation functions

Neighbour aggregation is a function over a multiset (a set with repeats). Assume one-hot colours for clarity.

GCN (mean-pool) — Xu et al., Theorem

Element-wise mean, then Linear + ReLU. Cannot distinguish multisets with the same colour proportion. Linear+ReLU after the mean doesn't help — the information is already gone.

GCN mean-pool and GraphSAGE max-pool failure cases. slide 37 ↗

GraphSAGE (max-pool) — Xu et al., Theorem

MLP, then element-wise max. Cannot distinguish multisets with the same set of distinct colours. Even with an MLP first, max only reports which "features" occur at least once.

Is attention (GAT) injective on multisets?

No. Attention weights sum to 1, so GAT computes a weighted mean. If all neighbours are identical, any weighting gives the same output regardless of how many there are: \(\{a\}\) and \(\{a,a,a\}\) collide. GAT inherits the "same distribution" failure of mean-pooling (with learned reweighting it can break some other ties).

3 · GIN: the most expressive message-passing GNN

\[ \textbf{Theorem (Xu et al., ICLR 2019).}\quad \text{Any injective multiset function can be written as } \Phi\Big(\sum_{x\in S} f(x)\Big). \]

Notation. \(S\) is a multiset: a set that may contain repeated elements. Here it holds the features of a node's neighbours, e.g. {yellow, blue, blue}. A multiset function is injective if different multisets always give different outputs. \(x\in S\) ranges over the elements of \(S\), counting repeats, so a colour that appears twice is summed twice. \(f\) is a function applied to each element on its own (it maps features to vectors), and \(\Phi\) is a second function applied once to the summed vector. Both are non-linear in general. So the theorem says: transform each element, add up the results, then transform the sum.

Proof intuition: let \(f\) produce one-hot encodings of colours; their sum is the vector of counts, which retains everything about the multiset; \(\Phi\) then maps counts injectively wherever you need. (For countable feature spaces, \(f\) can be built so the sum is unique — e.g. \(f(x)=N^{-Z(x)}\) for an enumeration \(Z\).)

Model \(\Phi\) and \(f\) with MLPs — justified by the universal approximation theorem (Hornik 1989: a 1-hidden-layer MLP with enough hidden units approximates any continuous function). In practice 100–500 hidden units suffice. The result:

\[ \text{GIN aggregation: }\ \text{MLP}_\Phi\Big(\sum_{x\in S}\text{MLP}_f(x)\Big)\qquad\text{— injective, no failure cases.} \]

From aggregation to the full GIN layer: the WL connection

The Weisfeiler–Lehman (1-WL) colour refinement algorithm:

  1. Give every node an initial colour \(c^{(0)}(v)\).
  2. Refine: \(c^{(k+1)}(v)=\text{HASH}\big(c^{(k)}(v),\{\!\{c^{(k)}(u):u\in N(v)\}\!\}\big)\), with an injective HASH.
  3. Colour refinement: initial colours, aggregated colours, injective hash. slide 52 ↗
  4. After \(K\) steps, \(c^{(K)}(v)\) summarises \(v\)'s \(K\)-hop rooted subtree. Stop when colours stabilise. If two graphs' colour histograms differ, they are not isomorphic; if equal, WL says "possibly isomorphic".

GIN replaces HASH by a neural network over the tuple (root colour, neighbour multiset). A second theorem shows any injective function of that tuple can be modelled as

\[ \text{GINConv}\Big(c^{(k)}(v),\{c^{(k)}(u)\}_{u\in N(v)}\Big)=\text{MLP}_\Phi\Big((1+\epsilon)\,c^{(k)}(v)+\sum_{u\in N(v)}c^{(k)}(u)\Big) \]

with a learnable scalar \(\epsilon\). (If inputs are one-hot, the inner MLP\(_f\) can be dropped: sums of one-hots are already injective; \(\Phi\) produces "one-hot-like" features for the next layer.) The \((1+\epsilon)\) factor keeps the root distinguishable from a neighbour with the same colour.

Update targetUpdate function
WL kernelnode colours (one-hot)HASH
GINnode embeddings (low-dim vectors)GINConv (differentiable, learned)

GIN = differentiable WL. Advantages: low-dimensional embeddings capture fine-grained similarity (WL colours are either equal or not), and the update is trained for the task. Expressive power: exactly that of 1-WL — if GIN can distinguish two graphs, so can WL, and vice versa (HW1 Q3.3 asks you to prove one direction for any message-passing GNN).

4 · The bad news: what 1-WL (and so every MPNN) can't do

1-WL distinguishes most real-world graphs (Babai, Erdős, Selkow 1980; Cai, Fürer, Immerman 1992 for the precise limits), but:

  • It can't distinguish some basic pairs — e.g. two fused 5-rings vs two fused 6-rings with the same degree pattern (slide 60), or a 6-cycle vs two triangles.
  • It can't count cycles or cliques. That matters: cycles are chemistry (benzene's hexagon), cliques/quasi-cliques are fraud rings, protein complexes and dense communities.
  • What WL and GIN cannot see. slide 63 ↗

Ways out (Lecture 7): give nodes identity (ID-GNN, You et al. 2021), positions/distances (P-GNN, distance encodings, Li et al. 2020), or random/structural features (Kanatsoulis et al. 2024), or go to higher-order WL.

The mathematics, step by step

The question of this session is exact: which pairs of graphs can a message-passing GNN tell apart? The answer comes from one word, injective: a function that never maps two different inputs to the same output. The cards define the colour-refinement test that bounds every GNN, show with numbers why mean and max lose information and sum does not, derive the GIN layer, and state where even GIN stops.

Symbols used in this session

symbolmeaningwhat kind of object
\(c^{(k)}(v)\)colour of node \(v\) after \(k\) rounds of refinementa label from a countable set
\(\{\!\{\cdot\}\!\}\)multiset: a collection in which order does not matter but repetitions counte.g. \(\{\!\{a,a,b\}\!\}\neq\{\!\{a,b\}\!\}\)
\(\text{HASH}\)an injective function: different inputs always get different outputsfunction
\(S\)a multiset of neighbour vectorsmultiset
\(f,\ \Phi\)functions applied before and after the sum; realised by MLPsfunctions
\(\epsilon\)a number (fixed or learned) that weights the node's own vectorreal number
\(\mathbf h_v^{(k)}\)embedding of node \(v\) after \(k\) GNN layers; plays the role of \(c^{(k)}(v)\)vector

1Colour refinement (the 1-WL test)

\[ c^{(k+1)}(v)=\text{HASH}\Big(c^{(k)}(v),\ \big\{\!\!\big\{c^{(k)}(u):u\in N(v)\big\}\!\!\big\}\Big) \]

In words. Give all nodes the same colour. In every round, a node's new colour is a code for the pair (its old colour, the multiset of its neighbours' colours). Stop when the grouping of nodes no longer changes; two graphs are declared different if their colour counts differ.

Why it has this form. After \(k\) rounds, a colour encodes the whole tree of neighbours-of-neighbours down to depth \(k\) (the rooted subtree, or computation tree). Because HASH is injective, two nodes share a colour exactly when these trees are identical. A GNN layer has the same shape: new vector = function of (own vector, multiset of neighbour vectors). So a GNN can separate two nodes only if 1-WL separates them: GNN ≤ 1-WL.

With numbers. Path 1–2–3. Round 0: all nodes colour \(a\). Round 1: the ends see \((a,\{\!\{a\}\!\})\), the middle sees \((a,\{\!\{a,a\}\!\})\); two different inputs, so two colours: ends \(b\), middle \(c\). Round 2 gives ends \((b,\{\!\{c\}\!\})\), middle \((c,\{\!\{b,b\}\!\})\): the same grouping, so stop. A triangle stays one colour for ever, because every node always sees \((a,\{\!\{a,a\}\!\})\).

Watch out. 'Same colours' does not prove two graphs are the same (isomorphic): the test can only prove a difference. Card 4 gives the standard pair it cannot separate.

2Sum is injective on multisets; mean and max are not

\[ \text{any injective multiset function can be written as}\quad g(S)=\Phi\Big(\sum_{x\in S}f(x)\Big) \]

In words. If the elements are first sent through a suitable function \(f\) and then added, the sum still determines the whole multiset; a second function \(\Phi\) can then turn it into any output.

Why it has this form. Take \(f\) = one-hot encoding of the element. The sum of one-hot vectors is the vector of counts: how many times each element occurs. The counts are the multiset, so nothing is lost. The mean divides the counts by the size, keeping only proportions; the max keeps only which elements occur at all. So mean cannot count and max cannot see repetitions.

With numbers. Two colours, \(a=(1,0)\) and \(b=(0,1)\). Compare \(S_1=\{\!\{a,b\}\!\}\) and \(S_2=\{\!\{a,a,b,b\}\!\}\). Sum: \((1,1)\) and \((2,2)\), different. Mean: \((0.5,0.5)\) and \((0.5,0.5)\), equal. Max: \((1,1)\) and \((1,1)\), equal. For \(S_3=\{\!\{a,a,b\}\!\}\): sum \((2,1)\), mean \((0.67,0.33)\), max \((1,1)\): mean now differs from \(S_1\), max still does not.

Watch out. One-hot codes need a countable set of possible inputs. For real-valued features the statement needs extra conditions, and in practice sum aggregation can be harder to train than mean because its scale grows with degree.

3The GIN layer

\[ \mathbf{h}_v^{(k+1)}=\text{MLP}^{(k)}\Big((1+\epsilon^{(k)})\,\mathbf{h}_v^{(k)}+\sum_{u\in N(v)}\mathbf{h}_u^{(k)}\Big) \]

In words. Add up the neighbours' vectors, add the node's own vector multiplied by \(1+\epsilon\), and send the result through a small multi-layer network.

Why it has this form. This is card 2 turned into a layer. The MLP of the previous layer plays the role of \(f\), the sum is the injective aggregation, and the MLP of this layer plays \(\Phi\) (an MLP can approximate any continuous function). The factor \(1+\epsilon\) is there so that the node itself is not confused with its neighbours: the pair (own colour, multiset of neighbour colours) must be encoded injectively, not just the multiset of all of them together.

With numbers. Colours \(a=(1,0)\), \(b=(0,1)\). Node \(v\) has colour \(b\) and neighbours \(\{\!\{a,b\}\!\}\); node \(w\) has colour \(a\) and neighbours \(\{\!\{b,b\}\!\}\). With \(\epsilon=0\) both give \(a+2b=(1,2)\): a collision, although 1-WL separates them. With \(\epsilon=0.5\): \(v\) gives \(1.5b+a+b=(1,2.5)\), \(w\) gives \(1.5a+2b=(1.5,2)\): separated.

Watch out. GIN is as strong as 1-WL, not stronger. 'Most expressive message-passing GNN' means it reaches the bound of card 1, and it says nothing about accuracy on a given data set.

4Where 1-WL, and therefore every such GNN, stops

\[ G \text{ is } d\text{-regular}\ \Longrightarrow\ c^{(k)}(v)=c^{(k)}(w)\ \text{ for all nodes } v,w \text{ and all } k \]

In words. If every node has the same degree and all nodes start with the same colour, all nodes keep the same colour in every round. Two regular graphs with the same degree and the same number of nodes cannot be told apart.

Why it has this form. By induction: if all nodes have colour \(c\) in round \(k\), each node sees \((c,\{\!\{c,\dots,c\}\!\})\) with exactly \(d\) copies, the same input everywhere, hence the same new colour. The computation trees are identical: every node has \(d\) children, each of which has \(d\) children, and so on. Whether the neighbours are linked to each other (a cycle closing after 3 steps or after 6) never appears in the tree.

With numbers. A hexagon and two separate triangles: both have 6 nodes, all of degree 2. Every node sees \((a,\{\!\{a,a\}\!\})\) for ever, so both graphs end with six nodes of one colour, and any GNN with identical input features gives them the same embedding. Yet one has 2 triangles and is disconnected, the other has none and is connected.

Watch out. The limit assumes all nodes start with the same features. Give nodes distinguishing features (random values, positions, counts of cycles) and the argument fails: that is the programme of Lecture 7.

Check yourself

Questions from the lecture, in order. Answer each one in your head (or on paper) before you open it. If one stumps you, follow the link to the walkthrough block it comes from.

Check yourself: nodes 3 and 1 — what is the quickest structural difference? show answer

Degree 1 vs degree 2.

from Local neighbourhood structures

Check yourself: is injectivity on the multiset of neighbours enough, or must the root's own embedding also be included? show answer

Both: the tree at the next level is determined by the root's previous state and the multiset of children. GIN handles this with the \((1+\epsilon)\) term below.

from Injectivity: what the most expressive GNN must do

Check yourself: does mean pooling fail on graphs where every node has the same feature? show answer

Yes, totally: the mean of any number of identical vectors is that vector, so mean-GCN cannot even count degrees. Sum can.

from Aggregation as a multiset function: where GCN and GraphSAGE fail

Check yourself: why does WL compare the multiset of colours of the two graphs, not the colours node by node? show answer

(Because there is no fixed node ordering — an isomorphism may permute the nodes.) And note the one-sided logic: different colour multisets prove non-isomorphism, but equal multisets do not prove isomorphism.

from The Weisfeiler–Lehman colour-refinement algorithm

Check yourself: in the two-pentagons vs two-hexagons example, why do all nodes of degree 3 get the same WL colour in both graphs? show answer

Each degree-3 node has neighbours with degrees {2, 2, 3} in both graphs, and each degree-2 node sees the same multiset of degrees in both too; the colouring is already stable after one round, and the colour counts match.

from Limits of WL and GIN: cycles and cliques

Lecture walkthrough reference · slide by slide · opens on demand

The whole lecture in order, grouped by topic. Every drawing on the slides is redrawn here as a clean figure (click the step buttons where a figure has them), the heading of each block links to the matching pages of the official PDF, and the Review section after the walkthrough ties this session to the earlier ones. Read this and you do not need the deck.

  1. Why ask how powerful GNNs are?
  2. The setting: message-passing GNNs and their boxes
  3. Local neighbourhood structures
  4. Computational graphs are rooted subtrees
  5. Injectivity: what the most expressive GNN must do
  6. Aggregation as a multiset function: where GCN and GraphSAGE fail
  7. An injective multiset function and the Graph Isomorphism Network
  8. The Weisfeiler–Lehman colour-refinement algorithm
  9. GIN as a neural Weisfeiler–Lehman kernel
  10. Limits of WL and GIN: cycles and cliques

Why ask how powerful GNNs are? slides 3-8 ↗

Slide 7: the classical expressivity test is graph isomorphism. The lecture studies the simpler question: which pairs of nodes can a message-passing GNN distinguish? slides 7-8 ↗

Slide 3 recalls where we are: the full GNN training pipeline from Lecture 5 (dataset split → input graph → GNN → node embeddings → prediction head → predictions, compared with labels by the loss function and the evaluation metrics). PyG provides the core modules for this pipeline, and GraphGym implements the full pipeline to help with GNN design.

Slide 4 reminds us of the variety of graphs: social networks, economic networks, citation networks, molecules. Slide 5: why is deep learning on graphs hard? Graphs are complex: they have a complex topological structure with no spatial locality like grids (images) or sequences (text), and there is no fixed node ordering or reference point.

Slide 6 poses the questions of this lecture. Many GNN models have been proposed (GCN, GAT, GraphSAGE, the whole design space of Lecture 4).

  • What is the expressive power of these models — their ability to distinguish different graph structures?
  • How do we design a maximally expressive GNN model?

Slide 7: a classical test of expressivity is graph isomorphism — given a pair of graphs, can we tell whether they are isomorphic (the same graph up to renaming the nodes)? The figure shows two drawings of 5-node graphs that look alike. Status of the problem: it is open: no polynomial-time algorithm is known, and it has not been proven NP-complete.

Slide 8 asks a simpler question that is the real focus: given a pair of nodes with different neighbourhood structures, is there a GNN that can always tell them apart? The figure shows a 5-node graph (edges 1–2, 1–5, 2–5, 5–4, 4–3) and, below it, the computation tree of each of its 5 nodes; the trees have different shapes.

Why "expressive power" matters: if a model maps two different structures to the same embedding, no prediction head can ever give them different labels. Expressiveness is an upper bound on what training can achieve, not a guarantee that training reaches it.

The setting: message-passing GNNs and their boxes slides 9-12 ↗

Slides 9–12: message-passing GNNs differ only in the aggregation box; GCN uses a mean, GraphSAGE a max. slides 9-12 ↗

Slide 9 fixes the class of models: message-passing GNNs. One layer has two steps:

\[ \text{(1) Message: }\ \mathbf{m}_u^{(l)}=\mathrm{MSG}^{(l)}\big(\mathbf{h}_u^{(l-1)}\big),\ u\in N(v)\cup\{v\};\qquad \text{(2) Aggregation: }\ \mathbf{h}_v^{(l)}=\mathrm{AGG}^{(l)}\Big(\big\{\mathbf{m}_u^{(l)},u\in N(v)\big\},\ \mathbf{m}_v^{(l)}\Big). \]

The figure: three coloured neighbour dots at the bottom send messages up into a box, which aggregates them into the node above.

Slide 10: different GNN models use different neural networks in the box. The figure shows the input graph with target node A and A's 2-layer computation tree; every aggregation box is marked with a question mark.

  • Slide 11, GCN (mean-pool) [Kipf and Welling, ICLR 2017]: element-wise mean pooling + Linear + ReLU non-linearity.
  • Slide 12, GraphSAGE (max-pool) [Hamilton et al., NeurIPS 2017]: MLP + element-wise max pooling.

The whole lecture is about one question: which choice of box loses the least information?

Local neighbourhood structures slides 13-17 ↗

Slides 13–17, the running graph: all nodes carry the same feature, so a GNN can only use local neighbourhood structure. slides 13-17 ↗

Slide 13 sets a convention: we use node colours to represent node features. Same colour = same feature. In the running example all nodes share the same feature (all yellow), so the only thing that can separate nodes is the structure. Key question: how well can a GNN distinguish different graph structures?

The running graph has 5 nodes and edges 1–2, 1–5, 2–5, 5–4, 4–3. Degrees: node 1: 2, node 2: 2, node 3: 1, node 4: 2, node 5: 3. We look at local neighbourhood structures around each node:

  • Slide 14: nodes 1 and 5 have different neighbourhood structures, because they have different degrees (2 vs 3).
  • Slide 15: nodes 1 and 4 both have degree 2. But they still have different neighbourhood structures, because their neighbours have different degrees: node 1 has neighbours of degrees 2 and 3; node 4 has neighbours of degrees 1 and 3.
  • Slide 16: nodes 1 and 2 have the same neighbourhood structure, because they are symmetric within the graph (swapping 1 and 2 maps the graph to itself). Node 1 has neighbours of degrees 2 and 3; so does node 2. Even going one step deeper, to 2nd-hop neighbours, both see the same degrees (node 4, of degree 2).

Slide 17: key question — can GNN node embeddings distinguish different nodes' local neighbourhood structures? If so, when? If not, when will a GNN fail? To answer, we need to understand how a GNN captures local neighbourhood structure. The key concept is the computational graph.

Check yourself: nodes 3 and 1 — what is the quickest structural difference? show answer

Degree 1 vs degree 2.

Computational graphs are rooted subtrees slides 18-24 ↗

Slides 18–21: a 2-layer GNN computes node 1 through its rooted computation tree. Nodes 1 and 2 have the same tree shape, so no message-passing GNN can tell them apart. slides 18-21 ↗
Slide 23: every node of the running graph with its rooted subtree. Nodes 1 and 2 share a shape; the other three differ. slides 22-24 ↗

Slide 18: in each layer, a GNN aggregates neighbouring node embeddings. So a GNN generates node embeddings through a computational graph defined by the neighbourhood. Example: node 1's computational graph for a 2-layer GNN. The root is 1; its children are its neighbours 2 and 5; the children of 2 are 1 and 5, and the children of 5 are 1, 2 and 4.

Slide 19 draws the computational graphs of nodes 1 and 2 side by side. Node 2's tree: root 2; children 1 and 5; under 1: 2 and 5; under 5: 1, 2, 4. Apart from the labels, the two trees have the same shape.

Slide 20: but a GNN only sees node features, not IDs. Erase the labels and both trees become identical trees of yellow dots. Slide 21: so a GNN will generate the same embedding for nodes 1 and 2, because (a) the computational graphs are the same and (b) the node features (colours) are identical. A GNN does not care about node IDs; it just aggregates the feature vectors of different nodes. The GNN will not be able to distinguish nodes 1 and 2.

Slide 22: in general, different local neighbourhoods define different computational graphs. The figure lists the 2-layer trees of all 5 nodes; e.g. node 3's tree is 3 → 4 → {3, 5}, a thin chain at the top, while node 5's tree starts with three branches.

Slide 23: computational graphs are identical to rooted subtree structures around each node — the structures you get by recursively unfolding neighbouring nodes from the root.

Slide 24: a GNN's node embeddings capture rooted subtree structures. The most expressive GNN maps different rooted subtrees to different node embeddings. In the figure, the embedding row above the trees uses colours: nodes 1 and 2 (same tree) get the same colour; nodes 3, 4, 5 each get their own colour.

So the right question is not "can the GNN tell nodes apart?" but "can it tell trees apart?". Nodes 1 and 2 are a case where no GNN of this kind can separate them — and, since they are truly symmetric, it also should not.

Injectivity: what the most expressive GNN must do slides 25-30 ↗

Slides 25–30: an injective map loses nothing. Subtrees are characterised recursively from the leaves up, so a GNN whose every aggregation step is injective separates different subtrees. slides 25-30 ↗

Slide 25 recalls a definition. A function \(f:X\to Y\) is injective if it maps different elements to different outputs. Intuition: \(f\) retains all the information about its input (you could in principle invert it). The figure maps elements 1, 2, 3 of \(X\) to three different elements of \(Y=\{A,B,C,D\}\).

Slide 26: the most expressive GNN should map subtrees to node embeddings in \(\mathbb{R}^d\) injectively.

Slide 27, key observation: subtrees of the same depth can be recursively characterised from the leaves to the root. Compare node 1 and node 4 with uniform input features. Node 1's root has 2 neighbours, which in turn have 2 and 3 neighbours: the description is (2 neighbours, 3 neighbours) under a 2-neighbour root. Node 4's root also has 2 neighbours, but they have 1 and 3 neighbours: (1 neighbour, 3 neighbours). The two descriptions differ, so the trees differ.

Slide 28: if each step of the GNN's aggregation can fully retain the neighbouring information, then the generated node embeddings can distinguish different rooted subtrees. The figure frames each level of the two trees: if level 1 keeps "2 neighbours" vs "1 neighbour, 3 neighbours" apart, and level 2 keeps the resulting multisets apart, the roots end up different.

Slide 29: in other words, the most expressive GNN uses an injective neighbour aggregation function at each step — it maps different neighbour multisets to different embeddings.

Slide 30 summarises: to generate a node embedding, a GNN uses a computational graph that is a subtree rooted at the node. A GNN can fully distinguish different subtree structures if every step of its neighbour aggregation is injective.

Why "every step"? The argument is an induction on depth. If depth-\(k\) embeddings already separate depth-\(k\) subtrees, and the aggregation is injective, then two depth-\((k+1)\) subtrees with different multisets of children get different embeddings. One non-injective step anywhere can merge two different trees, and nothing later can split them again.

Check yourself: is injectivity on the multiset of neighbours enough, or must the root's own embedding also be included? show answer

Both: the tree at the next level is determined by the root's previous state and the multiset of children. GIN handles this with the \((1+\epsilon)\) term below.

Aggregation as a multiset function: where GCN and GraphSAGE fail slides 32-40 ↗

Slides 33–40: aggregation is a multiset function. Mean cannot see multiplicities with the same proportions; max cannot see multiplicities at all. Sum sees the whole multiset. slides 33-40 ↗

Slide 32, key observation: the expressive power of a GNN is characterised by that of its neighbour aggregation function. A more expressive aggregation gives a more expressive GNN; an injective aggregation gives the most expressive GNN. Next: analyse the aggregation functions theoretically.

Slide 33: neighbour aggregation can be abstracted as a function over a multiset — a set with repeating elements. The figure shows a node with two yellow children as equivalent to the multiset {yellow, yellow}; other multiset examples: {yellow, blue} and {yellow, yellow, blue}. Same colour = same features.

Slide 34: we analyse two popular aggregators. GCN (mean-pool) uses element-wise mean pooling over neighbour features, \(\mathrm{Mean}(\{x_u\}_{u\in N(v)})\). GraphSAGE (max-pool) uses element-wise max pooling, \(\mathrm{Max}(\{x_u\}_{u\in N(v)})\).

GCN (slide 35): element-wise mean, then a linear function and ReLU, \(\max(0,x)\). Theorem [Xu et al., ICLR 2019]: GCN's aggregation function cannot distinguish different multisets with the same colour proportion. Failure case: {yellow, blue} vs {yellow, yellow, blue, blue}. Why? Slide 36: assume, for simplicity, node features (colours) are one-hot: yellow \(=(1,0)^\top\), blue \(=(0,1)^\top\); this is enough to show how GCN fails. Slide 37: the element-wise mean of \((1,0),(0,1)\) is \((0.5,0.5)\), and the mean of \((1,0),(1,0),(0,1),(0,1)\) is also \((0.5,0.5)\). After Linear + ReLU: the same outputs. Mean sees the distribution of colours, not the counts.

GraphSAGE (slide 38): apply an MLP, then take an element-wise max. Theorem [Xu et al., ICLR 2019]: GraphSAGE's aggregation cannot distinguish different multisets with the same set of distinct colours. Failure case: {yellow, blue}, {yellow, yellow, blue, blue} and {yellow, blue, blue}. Why? Slide 39: for simplicity, assume the MLP outputs a one-hot encoding (yellow → \((1,0)\), blue → \((0,1)\)). The element-wise max of any multiset that contains both colours is \((1,1)\). The same outputs. Max sees only the set of colours present.

Slide 40, summary so far:

  • The expressive power of GNNs can be characterised by that of the neighbour aggregation function.
  • Neighbour aggregation is a function over multisets (sets with repeating elements).
  • GCN's and GraphSAGE's aggregation functions fail to distinguish some basic multisets, hence they are not injective.
  • Therefore GCN and GraphSAGE are not maximally powerful GNNs.
Check yourself: does mean pooling fail on graphs where every node has the same feature? show answer

Yes, totally: the mean of any number of identical vectors is that vector, so mean-GCN cannot even count degrees. Sum can.

An injective multiset function and the Graph Isomorphism Network slides 41-47 ↗

Slides 41–47: the injective multiset function Φ(Σ f(x)) and its neural version, the Graph Isomorphism Network aggregation. slides 41-47 ↗

Slide 41, our goal: design the maximally powerful GNN in the class of message-passing GNNs. This is achieved by designing an injective neighbour aggregation function over multisets. We design a neural network that can model such a function.

Theorem (slide 42) [Xu et al., ICLR 2019]: any injective multiset function can be expressed as

\[ \Phi\Big(\sum_{x\in S}f(x)\Big), \]

where \(S\) is the multiset, \(f\) is some non-linear function applied to each element, the sum runs over the multiset, and \(\Phi\) is another non-linear function. The figure: the multiset {yellow, blue, blue} becomes \(\Phi(f(\text{yellow})+f(\text{blue})+f(\text{blue}))\).

Proof intuition (slide 43): let \(f\) produce one-hot encodings of colours. Then the sum of the one-hot encodings retains all the information about the input multiset — it is the vector of counts. Example: \((1,0)+(0,1)+(0,1)=(1,2)\): one yellow, two blue. Different multisets give different count vectors, and \(\Phi\) can then map these injectively wherever we want.

How do we model \(\Phi\) and \(f\)? Slide 44: with a multi-layer perceptron (MLP). Universal Approximation Theorem [Hornik et al., 1989]: a 1-hidden-layer MLP with a sufficiently large hidden dimension and an appropriate non-linearity \(\sigma(\cdot)\) (including ReLU and sigmoid) can approximate any continuous function to arbitrary accuracy. The figure: input → \(\mathbf{W}_1\) → \(\sigma\) → \(\mathbf{W}_2\) → output.

Slide 45: we have arrived at a neural network that can model any injective multiset function:

\[ \mathrm{MLP}_{\Phi}\Big(\sum_{x\in S}\mathrm{MLP}_f(x)\Big). \]

In practice, an MLP hidden dimension of 100 to 500 is sufficient.

Slide 46: the Graph Isomorphism Network (GIN) [Xu et al., ICLR 2019] applies an MLP, an element-wise sum, then another MLP. Theorem: GIN's neighbour aggregation function is injective. No failure cases! GIN is the most expressive GNN in the class of message-passing GNNs introduced so far.

Slide 47 discusses the power of pooling with the figure from the GIN paper. Top: three pairs of small neighbourhoods (colours = feature values) where (a) mean and max both fail, (b) max fails, and (c) mean and max both fail. Bottom: a ranking by discriminative power on an input multiset — sum captures the full multiset, mean captures the distribution (proportions), max captures only the underlying set: sum > mean > max.

A subtlety: the theorem is about countable feature spaces (e.g. one-hot or discrete features). With arbitrary real-valued features, sum can also collide (e.g. \(\{1,3\}\) and \(\{2,2\}\) have the same sum), which is exactly why \(f\) is applied before summing.

The Weisfeiler–Lehman colour-refinement algorithm slides 48-53 ↗

Slides 50–53, Weisfeiler–Lehman colour refinement: collect the neighbours' colours, hash the tuple injectively into a new colour, repeat. slides 50-53 ↗

Slide 48: so far we described GIN's neighbour aggregation. Now we describe the full GIN model by relating it to the WL graph kernel (a traditional way to obtain graph-level features, from Lecture 2). We will see that GIN is a "neural network" version of the WL kernel. Slide 49 repeats the graph isomorphism problem from slide 7: a classical expressivity test; open problem (no polynomial-time algorithm known, not proven NP-complete).

Colour refinement (slide 50). Given a graph \(G\) with node set \(V\):

  1. Assign an initial colour \(c^{(0)}(v)\) to each node \(v\).
  2. Iteratively refine node colours by \[ c^{(k+1)}(v)=\mathrm{HASH}\Big(c^{(k)}(v),\ \big\{c^{(k)}(u)\big\}_{u\in N(v)}\Big), \] where HASH maps different inputs to different colours.
  3. After \(K\) steps of colour refinement, \(c^{(K)}(v)\) summarises the structure of the \(K\)-hop neighbourhood.

Worked example on two graphs (slides 51–53). Both graphs have 6 nodes.

  • Slide 51: assign initial colour 1 to all nodes. Then each node collects its own colour and the multiset of its neighbours' colours, written as "own colour, neighbour colours": for example a node of degree 2 gets "1,11", a node of degree 4 gets "1,1111".
  • Slide 52: injectively HASH the aggregated colours, using the hash table 1,1 → 2; 1,11 → 3; 1,111 → 4; 1,1111 → 5. After this step the colour of each node is just its degree class; the next rounds repeat the process with the new colours.
  • Slide 53: the process continues until a stable colouring is reached (no colour class splits any more). Two graphs are considered isomorphic if they have the same set of colours. In the example the final colour multisets differ (the figure shows different colour labels such as 8, 10, 11 in the two graphs), so the two graphs are not isomorphic: \(\neq\).
Check yourself: why does WL compare the multiset of colours of the two graphs, not the colours node by node? show answer

(Because there is no fixed node ordering — an isomorphism may permute the nodes.) And note the one-sided logic: different colour multisets prove non-isomorphism, but equal multisets do not prove isomorphism.

GIN as a neural Weisfeiler–Lehman kernel slides 54-59 ↗

Slides 54–59: the complete GIN layer models the injective HASH over (root colour, neighbour colours); the table on slide 58 lines it up with the WL kernel. slides 54-59 ↗

Slide 54: GIN uses a neural network to model the injective HASH function \(c^{(k+1)}(v)=\mathrm{HASH}(c^{(k)}(v),\{c^{(k)}(u)\}_{u\in N(v)})\). Specifically, we model an injective function over the tuple (root node features \(c^{(k)}(v)\), neighbouring node colours \(\{c^{(k)}(u)\}_{u\in N(v)}\)).

Theorem (slide 55) [Xu et al., ICLR 2019]: any injective function over the tuple \(\big(c^{(k)}(v),\{c^{(k)}(u)\}_{u\in N(v)}\big)\) can be modelled as

\[ \mathrm{MLP}_{\Phi}\Big((1+\epsilon)\cdot\mathrm{MLP}_f\big(c^{(k)}(v)\big)+\sum_{u\in N(v)}\mathrm{MLP}_f\big(c^{(k)}(u)\big)\Big), \]

where \(\epsilon\) is a learnable scalar. The \((1+\epsilon)\) factor lets the network tell the root apart from its neighbours: without it, a root of colour A with neighbours {B} would give the same sum as a root of colour B with neighbours {A}.

Slide 56: if the input feature \(c^{(0)}(v)\) is one-hot, direct summation is already injective (example: \((1,0)+(0,1)+(0,1)=(1,2)\)). Then we only need \(\Phi\) to ensure injectivity:

\[ \mathrm{GINConv}\Big(c^{(k)}(v),\{c^{(k)}(u)\}_{u\in N(v)}\Big)=\mathrm{MLP}_{\Phi}\Big((1+\epsilon)\cdot c^{(k)}(v)+\sum_{u\in N(v)}c^{(k)}(u)\Big). \]

This MLP can provide "one-hot" input features for the next layer, so the argument repeats layer after layer.

GIN's node embedding updates (slide 57). Given a graph \(G\) with node set \(V\): assign an initial vector \(c^{(0)}(v)\) to each node; iteratively update node vectors by \(c^{(k+1)}(v)=\mathrm{GINConv}\big(\{c^{(k)}(v),\{c^{(k)}(u)\}_{u\in N(v)}\}\big)\), where GINConv is a differentiable colour HASH function that maps different inputs to different embeddings. After \(K\) GIN iterations, \(c^{(K)}(v)\) summarises the structure of the \(K\)-hop neighbourhood — exactly like WL.

Slide 58 compares them in a table. WL graph kernel: update target = node colours (one-hot); update function = HASH. GIN: update target = node embeddings (low-dimensional vectors); update function = GINConv. Advantages of GIN over the WL kernel:

  • Node embeddings are low-dimensional; hence they can capture the fine-grained similarity of different nodes (WL colours are either equal or different; there is no "almost the same").
  • The parameters of the update function can be learned for the downstream tasks.

Slide 59, expressive power of GIN: because of this relation, GIN and the WL kernel have exactly the same expressive power. If two graphs can be distinguished by GIN, they can also be distinguished by the WL kernel, and vice versa. How powerful is this? The WL kernel has been shown, both theoretically and empirically, to distinguish most real-world graphs [Cai et al. 1992]. (Citation note: the slide credits Cai, Fürer & Immerman 1992, but that paper is the negative result, that no fixed \(k\)-WL identifies all graphs. The positive "almost all graphs" result is Babai, Erdős & Selkow 1980, with Babai & Kučera 1979 for a linear-time canonical labelling.) Hence GIN is also powerful enough to distinguish most real graphs!

Precisely, the result has two halves: no message-passing GNN can be more powerful than 1-WL (any GNN's embedding is a function of the WL colour), and GIN, with injective layers, reaches 1-WL.

Limits of WL and GIN: cycles and cliques slides 60-64 ↗

Slides 60–64, the bad news: colour refinement cannot separate these two graphs and cannot count cycles or cliques; a triangle and a square give v₁ and v₂ identical computation trees. slides 60-64 ↗

Slide 60, the bad news: the WL kernel cannot distinguish some basic graph structures. The figure shows two 10-node graphs: two pentagons joined by an edge, and two hexagons sharing an edge. Every node has degree 2 or 3 in both, the degree patterns match, and colour refinement never separates them. Also, the WL kernel cannot count important substructures, such as cycles and cliques.

Why do these matter?

  • Cycles (slide 61): the bonds between atoms in chemical compounds form cycles. The hexagon is the most common polygon in organic compounds and yields stable materials. The figure shows three drug molecules (Doxorubicin, Camptothecin, Etoposide), each full of rings.
  • Cliques and quasi-cliques (slide 62): fraudster detection in e-commerce networks (an adjacency matrix where a dense block of fraudsters and "camouflage" edges to honest users stands out; Hooi et al. 2016), detection of protein complexes in protein–protein interaction networks (Vlasic et al. 2017), and graph compression (Dhulipala et al. 2017).

Slide 63: can the expressive power of GNNs be improved? There are basic graph structures the existing GNN framework cannot distinguish, such as differences in cycles: in the figure, \(v_1\) in graph A lies on a 3-cycle and \(v_2\) in graph B on a 4-cycle, yet their computational graphs are the same binary tree. GNNs' expressive power can be improved to resolve this [You et al. AAAI 2021; Li et al. NeurIPS 2020; Kanatsoulis et al. ICLR 2024] — the topic of Lecture 7.

Slide 64, summary of the lecture:

  • We designed a neural network that can model an injective multiset function.
  • Using it for neighbour aggregation gives GIN, the most expressive GNN model (among message-passing GNNs).
  • The key is element-wise sum pooling instead of mean or max pooling.
  • GIN is closely related to the WL graph kernel.
  • Both GIN and the WL kernel can distinguish most real graphs.
Check yourself: in the two-pentagons vs two-hexagons example, why do all nodes of degree 3 get the same WL colour in both graphs? show answer

Each degree-3 node has neighbours with degrees {2, 2, 3} in both graphs, and each degree-2 node sees the same multiset of degrees in both too; the colouring is already stable after one round, and the colour counts match.

Not shown (no new content): slides 1,2,31 — title page, announcements (Colab and homework deadlines, project proposal) and a section-divider title page.

Review: what to keep from this session

Carried forward. Lecture 7 adds positional and structural encodings to break the WL ceiling; Lecture 8 does it with graph transformers; Lecture 19's experiments confirm that sum aggregation is the most expressive choice in practice; Lecture 21 uses the "injective on multisets" idea for geometric and subgraph models.

Quick self-check

Why is injectivity the key property of an aggregator?

If two different multisets of neighbour vectors map to the same aggregated vector, the two nodes become indistinguishable from that layer on, so information is lost.

Why does the MLP in GIN matter?

The universal-approximation theorem lets a one-hidden-layer MLP represent any injective multiset function; sum alone needs a well-chosen encoding of the inputs.

Give a pair of graphs 1-WL cannot tell apart.

Two disjoint triangles and a six-cycle: all nodes have degree two with degree-two neighbours at every iteration.

Key idea

A message-passing GNN is at most as powerful as the 1-WL test; it reaches that bound exactly when every aggregation is injective on multisets — which sum aggregation with MLPs (GIN) achieves and mean/max do not.

\[ \mathbf{h}_v^{(k+1)}=\text{MLP}^{(k)}\Big((1+\epsilon^{(k)})\,\mathbf{h}_v^{(k)}+\sum_{u\in N(v)}\mathbf{h}_u^{(k)}\Big) \]

GIN layer. For graph classification, GIN reads out with a sum over nodes at every layer and concatenates them (the paper's readout).

Worked example: WL on a hexagon vs two triangles

\(G_1=C_6\) (one 6-cycle); \(G_2=C_3\cup C_3\) (two disjoint triangles). Both have 6 nodes, 6 edges, every degree 2.

  1. Iteration 0: all nodes colour 1. Histograms: \(G_1\): {1:6}, \(G_2\): {1:6}.
  2. Iteration 1: each node sees (1, {1,1}) → hash to colour 2 everywhere. Histograms still equal.
  3. Every later iteration: the same — every node in both graphs has an identical infinite binary computation tree. Colouring is stable after one step.
  4. Verdict: WL (and GIN, GCN, GAT, GraphSAGE…) says "possibly isomorphic". But \(G_1\) is connected and \(G_2\) isn't! No MPNN can even detect connectivity here.
  5. Escape: give one node a distinct colour (identity). In \(G_1\) the coloured signal returns to its origin after 6 steps; in \(G_2\) after 3. That's ID-GNN's idea (Lecture 7).

Strictly speaking: "GIN is as powerful as WL" is about the capacity of the function class (with suitable weights). Whether training actually finds injective weights, and whether that helps generalisation, are separate questions — GIN doesn't always win on benchmarks.

In code (PyG)

from torch_geometric.nn import GINConv, global_add_pool
from torch.nn import Sequential as Seq, Linear, ReLU, BatchNorm1d
def mlp(i, o): return Seq(Linear(i, o), BatchNorm1d(o), ReLU(), Linear(o, o))
conv1 = GINConv(mlp(d_in, 64), train_eps=True)    # (1+eps)*h_v + sum h_u, then MLP
conv2 = GINConv(mlp(64, 64), train_eps=True)
h1 = conv1(x, edge_index); h2 = conv2(h1, edge_index)
g = torch.cat([global_add_pool(h1, batch), global_add_pool(h2, batch)], dim=1)  # sum readout

Proof workshop: 1-WL is blind to regular graphs, and sums can encode multisets

One problem in olympiad style. Give it fifteen minutes on paper before you open the first hint; the hints are graded, so open them one at a time.

Problem. (a) Prove that 1-WL colour refinement cannot distinguish any two \(d\)-regular graphs with the same number of nodes. (b) (Xu et al., Lemma 5, the olympiad part.) Let \(\mathcal X\) be countable with an injection \(Z:\mathcal X\to\mathbb N\), fix an integer \(N\ge2\), and consider multisets of size less than \(N\). Prove that \(S\mapsto\sum_{x\in S}N^{-Z(x)}\) is injective.

Hint 1
(a) Induction on the round \(k\): suppose every node in both graphs has the same colour after round \(k\). What is every node's signature in round \(k+1\)?
Hint 2
(b) Write the sum as \(\sum_{z}m_zN^{-z}\), where \(m_z\) is the multiplicity of the element with \(Z(x)=z\). Which values can a digit \(m_z\) take?
Solution
(a) Round 0: one colour everywhere. If after round \(k\) all nodes share colour \(c_k\), every node's signature is \((c_k,\{\!\{c_k,\dots,c_k\}\!\})\) with exactly \(d\) copies, the same for every node of both graphs, so they all get one colour \(c_{k+1}\). The histograms are \(\{c_k:n\}\) in both graphs at every round. (b) Each multiplicity satisfies \(0\le m_z\le|S|\lt N\), so \(\sum_zm_zN^{-z}\) is a finite base-\(N\) expansion with digits \(m_z\). Finite base-\(N\) expansions are unique (the \(0.999\ldots\) ambiguity needs infinitely many nonzero digits), so the sum determines every \(m_z\), hence the multiset. \(\square\)

Why it matters. Part (a) is the cleanest statement of the WL ceiling: a 6-cycle and two triangles, the triangular prism and \(K_{3,3}\), or any pair of regular "bot rings" of the same size are invisible to every message-passing GNN. Part (b) is why sum (not mean, not max) is the right aggregator: bounded multisets embed injectively in \(\mathbb R\), and an MLP then only has to approximate a continuous map.

Sharper lens: one invariant, four descriptions

Not on the slides. Three or four points where the lecture rounds something off: the exact statement, a second way to see it, and where it stops being true. Each is short and has a pointer for going further.

second viewpoint

Four ways to say "1-WL cannot tell G from H"

The following are equivalent for graphs \(G,H\) with adjacency matrices \(A,B\). Each comes from a different field, and each is a tool.

  • Combinatorics. Colour refinement gives both graphs the same colour histogram; equivalently, they have a common equitable partition (every node of class \(i\) has the same number of neighbours in class \(j\)).
  • Counting. \(\hom(T,G)=\hom(T,H)\) for every tree \(T\), where \(\hom\) counts edge-preserving maps (Dvořák 2010; Dell, Grohe and Rattan 2018). A message-passing GNN knows the tree-homomorphism counts and nothing else.
  • Linear programming. An isomorphism is a permutation matrix \(P\) with \(AP=PB\). Relax "permutation" to "doubly stochastic": \(AS=SB\), \(S\ge0\), \(S\mathbf 1=S^\top\mathbf 1=\mathbf 1\). The relaxed system is solvable exactly when 1-WL fails to separate the graphs (Tinhofer 1986). WL is the LP relaxation of graph isomorphism.
  • Logic. \(G\) and \(H\) satisfy the same sentences of \(C^2\), first-order logic with counting quantifiers and two variables (Cai, Fürer and Immerman 1992).

The counting view gives the exact rule behind "cannot count cycles": the number of copies of a pattern \(F\) is a fixed linear combination of homomorphism counts of the homomorphic images of \(F\), so 1-WL determines it exactly when every such image is a forest. Identify the two ends of a 3-edge path and you get a triangle, so 1-WL cannot even count 3-edge paths. What survives is stars (Chen et al., NeurIPS 2020).

precise statement

"Sum is injective" is a statement about countable features

Xu et al.'s lemma (the proof workshop) needs a countable feature space. Node features in practice are real vectors, and there the picture changes. For multisets of \(n\) real numbers, a continuous sum-decomposition \(\Phi\big(\sum_xf(x)\big)\) needs the sum to live in at least \(n\) dimensions (Wagstaff et al. 2019), which is why Principal Neighbourhood Aggregation (Corso et al., NeurIPS 2020) combines several aggregators and degree scalers: for continuous features, mean, max and standard deviation carry information that one sum of fixed width does not.

The activation matters too. For multisets of \(n\) vectors in \(\mathbb R^d\), a sum of \(2nd+1\) neurons with an analytic non-polynomial activation (tanh, sigmoid, softplus) is injective for almost all weights, whereas with ReLU no finite width is injective (Amir et al., NeurIPS 2023). "GIN is as powerful as WL" on real-valued features is therefore a statement about width and activation, not only about choosing sum.

where it breaks

The logic bridge, stated exactly

Barceló et al. (ICLR 2020) is often quoted as "GNNs = \(C^2\)". The theorem has two halves. A node classifier definable in first-order logic can be computed by an aggregate-combine GNN if and only if it is in graded modal logic: formulas built from "at least \(k\) neighbours satisfy \(\varphi\)". That logic can only talk about what is reachable from the node. Full \(C^2\) can also say "somewhere in the graph there are at least \(k\) nodes with \(\varphi\)", and capturing it needs a global readout at every layer (their ACR-GNNs; a virtual node is the practical form). So: without readout, graded modal logic, exactly; with readout, everything in \(C^2\). And both statements concern which logical classifiers a GNN can express; a GNN with real weights can also compute things no first-order formula defines.

Lab: hands-on and practical tips

Try it live. In the Graph Explorer: step 1-WL on the hexagon and the two triangles, then on the karate club. Each lesson has predict-then-check questions.

notebook · L06 theory of GNNs tests injectivity of aggregators on multisets, implements the WL test, counts with GIN, and runs the benchmark above against a WL kernel.

"As powerful as WL" is a capacity statementSome weights exist that make GIN injective. Whether training finds them, and whether injectivity helps generalisation, are separate questions. In the notebook's benchmark (3 seeds × 5 folds) the WL kernel plus a linear SVM is best on PROTEINS (0.752) and IMDB-BINARY (0.722); GIN wins only on MUTAG (0.863). Always report a simple baseline (WL kernel, degree histogram + logistic regression, MLP on pooled features), and follow Errica et al. (2020) on splits and model selection.
Ablate before you explain"GIN beats GCN" changes the layer, the readout and the update at once. Crossing them on featureless IMDB-BINARY: GCN 0.531 (mean readout) / 0.500 (sum), GIN 0.703 / 0.681. The layer decides it; sum readout is not even better here. Why the GCN layer fails: on a \(d\)-regular graph, its normalised sum maps a constant signal to \(\frac{(d+1)c}{d+1}=c\) for every degree, and IMDB ego-networks are dense and nearly regular. GIN's plain sum gives \((d+1)c\), which counts.
Sum, then MLP; not MLP, then meanInjectivity needs the sum over an encoded multiset followed by a universal approximator. GINConv(nn.Sequential(Linear, ReLU, Linear)) with train_eps=True is the reference layer; aggr="mean" throws the theorem away.
Measure your own WL ceilingRun three rounds of colour refinement on your graph (NetworkX: weisfeiler_lehman_subgraph_hashes) and count how many nodes share a colour. If many do, no message-passing model can separate them without extra features (Lecture 7).
Cliques and cycles are invisibleCoordinated inauthentic behaviour often forms cliques or quasi-cliques; a 6-cycle and two triangles are identical to 1-WL. Add triangle and clique counts as features, or use a subgraph-aware GNN, before concluding that "the GNN found nothing".

Readings & lookup guide

lecture notes CS224W course notes (Leni Aniva, Autumn 2024 — in your course folder)

Concise written version of the lectures; the walkthrough above cites it page by page.

must read Xu, Hu, Leskovec, Jegelka — How Powerful are Graph Neural Networks? (GIN, ICLR 2019)

arXiv:1810.00826 · 17 pages incl. proofs · ~3 h · one of the most important theory papers in the field
  • Read: §2 (WL background), §3 (Lemma 2: GNNs ≤ WL; Theorem 3: conditions for equality), §4.1 (GIN; Lemma 5 & Corollary 6 — the sum decomposition), §5 (why mean/max are less powerful, Fig. 2–3).
  • Work through yourself: the proof of Lemma 5 — it's an elegant olympiad-style construction (encode a countable set so sums are unique). Try it before reading.
  • Skim: §6–7 experiments; note GIN fits training data almost perfectly while GCN/SAGE underfit — evidence of expressive power, not of generalisation.
  • Related (Lecture 7 & HW1 Q3.3): Morris et al., "Weisfeiler and Leman Go Neural" (AAAI 2019) — proved the same WL equivalence independently and introduced \(k\)-GNNs.

background Shervashidze et al. — Weisfeiler–Lehman Graph Kernels (JMLR 2011)

The classical WL kernel; read §3 only (~30 min).
  • Shows the pre-neural use of colour refinement as a graph feature extractor — useful context for "GIN as a neural WL kernel".

method Errica, Podda, Bacciu & Micheli — A Fair Comparison of Graph Neural Networks for Graph Classification (ICLR 2020)

arXiv:1912.09893 · ~1 h · the paper behind the notebook's benchmark protocol
  • Re-ran GIN, DGCNN, DiffPool and others on MUTAG, PROTEINS, IMDB and more with fixed splits and proper model selection: a structure-agnostic baseline often matches them.
  • Read it before trusting any graph-classification table, including the notebook's: average over seeds, separate model selection from assessment, report a baseline.

survey Morris et al. — Weisfeiler and Leman go Machine Learning: The Story so far (JMLR 2023)

arXiv:2112.09992 · long survey — use as a lookup reference
  • Look up: \(k\)-WL hierarchy, logical characterisation (counting logic \(C^2\)), and which substructures each level can count.

Homework & Colabs connected to this lecture

Homework 1 · Q3 (GCN / WL, 11 pts) due Thu 10/15

  • Q3.1 Are two given graphs isomorphic? Give a bijection or an invariant that differs.
  • Q3.2 Construct graphs where mean and max give equal updates but sum differs — exactly row 2 of the picture (e.g. neighbour features {1} vs {1,1}).
  • Q3.3 Prove any AGGREGATE/COMBINE/READOUT model is at most as powerful as WL. Hint: induction on \(k\) — if WL colours agree at iteration \(k\), then GNN embeddings agree; contrapositive at the readout.
  • Also Q1.1: the depth needed to separate two nodes = the first depth where their rooted subtrees differ.

Colab 2 out Thu 10/8 · due Thu 10/22

In earlier offerings: explore PyG datasets (TUDataset, Planetoid), then implement a GCN for node property prediction on OGB ogbn-arxiv and a GNN + global pooling for graph property prediction on ogbg-molhiv (ROC AUC via the OGB evaluator). This lecture suggests an experiment: swap mean pooling for global_add_pool and GCN for GIN and compare. Link appears on the course site once released.

Self-check

Two nodes get the same embedding from every message-passing GNN when …

  1. they have the same degree
  2. their rooted subtrees (with features) are identical
  3. they are in the same community
  4. they have the same PageRank

The computation graph is the rooted subtree; same tree + same features ⇒ same output.

Max pooling cannot distinguish …

  1. {a, b} from {a}
  2. {a, b} from {c}
  3. {a, b} from {a, a, b}
  4. {a} from {b}

Same set of distinct elements ⇒ same element-wise max.

What does the \((1+\epsilon)\) in GIN do?

  1. Keeps the root's own feature distinguishable from neighbours' sum
  2. Normalises by degree
  3. Adds dropout
  4. Implements attention

Without it, (root a, neighbours {b}) and (root b, neighbours {a}) could collide.

Which pair can 1-WL NOT distinguish?

  1. A star and a path on 4 nodes
  2. Graphs with different numbers of edges
  3. A triangle and a path of 3 nodes
  4. A 6-cycle and two disjoint triangles

All nodes have degree 2 in both → identical refinement at every step.

The theorem that justifies modelling \(\Phi\) and \(f\) with MLPs is …

  1. the spectral theorem
  2. the universal approximation theorem
  3. Weisfeiler–Lehman's theorem
  4. the Perron–Frobenius theorem

Hornik (1989): 1-hidden-layer MLPs approximate any continuous function.

Flashcards (click to flip)

Injective function
Different inputs → different outputs; keeps all information.
Mean pooling fails on…
multisets with the same colour proportions.
Max pooling fails on…
multisets with the same set of distinct colours.
Injective multiset function form
\(\Phi(\sum_{x\in S}f(x))\)
WL refinement step
\(c^{k+1}(v)=\text{HASH}(c^k(v),\{\!\{c^k(u)\}\!\}_{u\in N(v)})\)
GIN vs WL
Exactly equally expressive; GIN is low-dim and learnable.
What 1-WL can't count
Cycles, cliques; can't separate many regular graphs.

History & the bigger picture

  • 1968 — Weisfeiler & Leman (Boris Weisfeiler and Andrei Leman, in the USSR) publish the reduction of a graph to a canonical form — the origin of colour refinement. Weisfeiler later emigrated to the US and disappeared in Chile in 1985 under the Pinochet regime; the mathematics outlived the politics that silenced its author.
  • 1979–1992 — complexity of graph isomorphism: Babai–Erdős–Selkow (WL works for almost all random graphs), Cai–Fürer–Immerman (1992: no fixed \(k\)-WL solves isomorphism; ties to counting logics).
  • 2015–2016 — Babai's quasi-polynomial algorithm for graph isomorphism — a landmark in TCS; GI is still neither known in P nor NP-complete.
  • 2019 — GIN and "WL go neural" bring this classical theory into deep learning and launch the "expressivity" research programme.
Philosophy · what can a local observer know?

WL formalises an epistemic limit: an agent that only ever hears what its neighbours report (and can count them) cannot know global facts like "am I on a cycle of length 6?" if the world is symmetric enough. The same theme appears in distributed computing (anonymous networks can't break symmetry — Angluin 1980) and in social epistemology: individuals embedded in identical local social positions may hold identical beliefs regardless of the global structure.

Classic SNA bridge

In this lectureClassic SNA counterpartWhat carried over, what changed
1-WL colour refinementRegular equivalence (White & Reitz 1983); the CATREGE and REGE algorithmsThe same iterative refinement: two nodes are equivalent if they are connected to equivalent others. SNA computed it to find roles; graph ML rediscovered it as the ceiling of message passing.
Injective aggregation over a multisetCounting ties by type: the degree sequence, the triad census as a multiset of neighbourhood typesSociologists counted; mean-aggregating GNNs cannot. GIN restores counting, and with it the ability to express "has at least k ties of type X", the basic predicate of role analysis.
Computation graphs are rooted subtreesEgo networks of radius \(K\); the "tree-like" approximation in network epidemiologyA subtree ignores the cycles that make a neighbourhood social (closure, cliques). SNA knew ego-network density matters; the WL blind spot is the formal statement that the subtree view misses it.
Limits of WL: cycles and cliquesClustering coefficient, transitivity, Simmelian ties (Krackhardt 1999)Everything SNA considers the signature of a social group is exactly what 1-WL cannot see. That is why hand-made triangle counts remain informative features in 2026.
Graph isomorphism as the limiting problemStructural comparison of networks; network "superfamilies" by significance profiles (Milo et al. 2004)SNA compared networks by motif profiles, a lossy but informative invariant; graph ML discovered its models compute a different lossy invariant (WL) and is now cataloguing which patterns each sees.
Bridge idea

Run regular-equivalence (REGE) and 3-round WL on the same directed retweet graph and compare the partitions. Where they differ, the difference is the directed, weighted information REGE uses and plain WL discards; that gap suggests which edge features to add to a GNN for role-based bot detection.

Go deeper in the SNA course. The twelve-unit course on social network analysis in this repository gives the classic side of this lecture in full, with labs and real-data analyses: Unit 1 · Ties, triads & the roots of SNA (why message passing (1-WL) cannot count the triangles this unit is built on); Unit 10 · Causality, interference & graph ML (the WL bound on expressive power).

Connecting to your research

Running project. Section L06–L07 · rings that look normal of notebooks/project/retweet_thread.py applies this lecture to one synthetic X world with coordinated rings, the same graph across the whole course. The companion study experiments/rege-vs-wl runs this lecture's SNA bridge (regular equivalence = set refinement, WL = multiset refinement) as a small experiment.

For neuro-symbolic and SNA work
  • Logic ↔ GNNs: Barceló et al. (ICLR 2020), "The logical expressiveness of GNNs": among first-order node classifiers, aggregate-combine GNNs capture exactly graded modal logic, the fragment of the 2-variable counting logic \(C^2\) that only looks along edges; all of \(C^2\) needs a global readout (see the Sharper lens). This is a precise neuro-symbolic bridge — an excellent anchor for a proposal on interpretable or verifiable GNNs.
  • SNA: WL colours are a form of regular equivalence (White & Reitz 1983) — nodes are equivalent if they're connected to equivalent others. Classic SNA already has a vocabulary for this (roles, positions, equivalence classes) that ML papers often reinvent; your SNA work gives you that vocabulary.
  • Practical: coordinated inauthentic behaviour often forms cliques/quasi-cliques — exactly what MPNNs can't count. Add clique/triangle counts as features or use subgraph-aware GNNs (Lecture 7).

From the experiments: results and datasets

Generated by scripts/sync_guides.py from the experiments' committed results and the dataset catalogue; rerun it (make sync-guides) after an experiment changes.

rege-vs-wl

Question. Regular equivalence (sets of neighbour roles) or WL (multisets): which separates rings? experiment folder ↗

Rings of random size, cross-validated AUC by aggregator. Best on co-amplification rings: directed · sum (0.914); set-style aggregators (max) stay near 0.5.

Datasets for this session

From the repo's catalogue (gl.datasets; the full list with sources and licences is in data/README.md). Load one with gl.datasets.graph(name), temporal(name) or node_data(name).

namedatasetnodesground truthgood for
imdb-binaryIMDB-BINARY ego networks1,000genre (2), per graphsocial graph classification (TUDataset)
reddit-binaryREDDIT-BINARY threads2,000Q&A vs discussion (2), per graphsocial graph classification on discussion threads (TUDataset)

Frontier 2025–26: what changed since the slides

ICML 2024 → 2026From "can it separate?" to "can it learn, and how hard is it?" — The Morris et al. position paper argued that theory was too focused on coarse-grained expressive power; by 2026 the sharp results are about learnability: Message Passing Complexity (NeurIPS 2025 spotlight) measures task difficulty continuously, and Wittig et al. (ICML 2026 oral) prove which algorithms GNNs can learn with size generalisation, plus impossibility results.sources: arXiv:2509.01254 · arXiv:2602.13106
ICLR 2024 oralHomomorphism expressivity — Zhang et al. replace the yes/no "does it beat 1-WL?" question with the exact family of patterns whose counts a model can compute (1-WL = tree homomorphism counts, Dell–Grohe–Rattan 2018). This is the fine-grained version of the lecture's "cycles and cliques" limitation.sources: arXiv:2401.08514
ICML 2026 spotlightsEquivariant use of noise; exact algorithm execution — "Expressive GNNs via equivariant use of noise" revisits random features as a principled way past WL; "Learning to execute graph algorithms exactly" shows BFS, DFS and Bellman–Ford can run without error with bounded degree and finite precision. The injectivity argument of this lecture is the starting point of both.sources: arXiv:2502.02479 · arXiv:2601.23207
ICLR 2020 → LICS 2021The logic bridge — Barceló et al.: aggregate-combine GNNs capture exactly graded modal logic (formulas with "at least k neighbours satisfy φ"). Grohe's "Logic of GNNs" makes the triad combinatorics = logic = algebra precise; Schönherr & Lutz (AAAI 2026) show the uniform-vs-non-uniform distinction changes the answer for mean aggregation.
ICLR 2026The same triad for topological networks — Akbari, Souza & Garg give combinatorial-complex networks a Weisfeiler–Leman test, a counting logic and a pebble game, the three-way characterisation GNNs got around 2020. Expressivity theory now covers hypergraphs and complexes.
Open question to carryWhich notion of expressivity actually predicts performance on real tasks? The atlas lists this as the open question of the whole cluster; Message Passing Complexity is the first continuous candidate.
Frontiers · colour refinement animation · three languages, one invariant · the 2024–26 turn · architectures and their logics

Words & phrases

TermSimple meaningPersianIn context
injectiveadj.a function that never maps two different inputs to the same output (one-to-one)یک‌به‌یک"every aggregation step is injective"
expressive powern.what a model class can tell apart or represent, regardless of trainingتوان بیانی"GIN has the expressive power of 1-WL"
regular graphn.a graph in which every node has the same degreeگراف منتظم"1-WL cannot separate regular graphs of equal size"
upper boundn.a limit that a quantity can reach but not exceedکران بالا"WL is an upper bound on message passing"
contrapositiven.the equivalent statement "if not B then not A" of "if A then B"عکس نقیض"prove it via the contrapositive"

Also: refinement (making a partition finer — پالایش، ریزسازی), isomorphic (یکریخت), multiset (چندمجموعه).

Go deeper

  • Next: Lecture 7 — breaking the WL ceiling: identity-aware, position-aware and substructure-counting GNNs.
  • Logic: Grohe (2021), "The logic of graph neural networks" (LICS) — a beautiful short survey for a mathematician.
  • Open question: expressiveness vs generalisation. More expressive models can overfit; Morris et al. (2023) and Garg et al. (2020) study VC/Rademacher bounds tied to WL colours. Which notion of "power" actually predicts performance on social graphs?