Part XXII — Graph Neural Networks & Structured Data · Chapter 2

Message passing & the GCN

Hook

Every node in the last chapter's graph carries its own number. What's the simplest possible way to let a node's value be influenced by where it sits in the graph, not just its own starting value?

Intuition
01.012.020.033.041.052.0
round 0

Click "pass one round of messages" a few times. Every node's number nudges toward the average of itself and its direct neighbors — nothing fancier than that.

Formalize

A Graph Convolutional Network (GCN) layer replaces the standard neural-net update with message passing: each node's new feature is a function of the (multi-)set of its neighbors' current features, plus its own:

hv(k+1)=AGGREGATE(hv(k),  {hu(k):uN(v)})h_v^{(k+1)} = \text{AGGREGATE}\Big(h_v^{(k)}, \; \{h_u^{(k)} : u \in \mathcal{N}(v)\}\Big)
  • hv(k)h_v^{(k)} — node vv's feature after kk rounds of message passing.
  • hv(k+1)h_v^{(k+1)} — node vv's updated feature after one more round of message passing.
  • hu(k)h_u^{(k)} — a neighbor uu's current feature, one of the values node vv aggregates.
  • N(v)\mathcal{N}(v) — node vv's neighborhood: every node it shares an edge with.
  • AGGREGATE — the combining function; this chapter fixes it to a plain mean of the node and its neighbors.
  1. AGGREGATE fixed to a plain mean

    The simplest possible choice of AGGREGATE — the one this chapter uses — is a plain mean: average the node's own value together with every neighbor's.

  2. Stacking layers reaches further hops

    Stack kk of these layers, and information from nodes up to kk hops away has had a chance to reach any given node.

Play
01.012.020.033.041.052.0
round 0 — variance across all nodes = 0.9167

Watch the variance number, not just the graph. It shrinks every single round — nodes that started far apart in value are ending up closer and closer together. That's not a bug; it's exactly what averaging repeatedly does, and it's the double-edged sword of stacking too many GCN layers: over-smoothing.

Worked example

Starting features x=(1,2,0,3,1,2)x=(1,2,0,3,1,2) for nodes (0,1,2,3,4,5)(0,1,2,3,4,5):

  1. One round, computed by hand for a leaf and a hub
    • Node 44 (a leaf, neighbor {3}\{3\}): h4(1)=1+32=2h_4^{(1)} = \frac{1+3}{2} = 2.
    • Node 33 (a hub, neighbors {1,4,5}\{1,4,5\}): h3(1)=3+2+1+24=2h_3^{(1)} = \frac{3+2+1+2}{4} = 2.

    Every node's group size is 1+deg(v)1+\deg(v) — the denominator changes depending on the node, since degrees aren't uniform (Chapter 1).

  2. Full round 1

    The same mean rule for the remaining four nodes:

    • h0(1)=1+2+03=1.0h_0^{(1)} = \frac{1+2+0}{3} = 1.0 (self 11, neighbors {1,2}\{1,2\} with features 2,02,0)
    • h1(1)=2+1+0+34=1.5h_1^{(1)} = \frac{2+1+0+3}{4} = 1.5 (self 22, neighbors {0,2,3}\{0,2,3\} with features 1,0,31,0,3)
    • h2(1)=0+1+23=1.0h_2^{(1)} = \frac{0+1+2}{3} = 1.0 (self 00, neighbors {0,1}\{0,1\} with features 1,21,2)
    • h5(1)=2+32=2.5h_5^{(1)} = \frac{2+3}{2} = 2.5 (self 22, neighbor {3}\{3\} with feature 33)

    Together with h3(1)=2.0h_3^{(1)}=2.0 and h4(1)=2.0h_4^{(1)}=2.0 from the step above: h(1)=(1.0, 1.5, 1.0, 2.0, 2.0, 2.5)h^{(1)} = (1.0,\ 1.5,\ 1.0,\ 2.0,\ 2.0,\ 2.5).

    The new mean is 1.0+1.5+1.0+2.0+2.0+2.56=10.061.667\frac{1.0+1.5+1.0+2.0+2.0+2.5}{6}=\frac{10.0}{6}\approx1.667, so the new variance is (1.01.667)2+(1.51.667)2+(1.01.667)2+(2.01.667)2+(2.01.667)2+(2.51.667)261.83360.306\frac{(1.0-1.667)^2+(1.5-1.667)^2+(1.0-1.667)^2+(2.0-1.667)^2+(2.0-1.667)^2+(2.5-1.667)^2}{6} \approx\frac{1.833}{6}\approx0.306 — down from the original 11120.917\frac{11}{12}\approx0.917, already less than a third of where it started.

  3. Keep going and it keeps shrinking

    Running the identical mean rule for three more rounds:

    • Round 22: h(2)(1.167, 1.375, 1.167, 2.0, 2.0, 2.25)h^{(2)} \approx (1.167,\ 1.375,\ 1.167,\ 2.0,\ 2.0,\ 2.25), variance 0.191\approx0.191
    • Round 33: h(3)(1.236, 1.427, 1.236, 1.906, 2.0, 2.125)h^{(3)} \approx (1.236,\ 1.427,\ 1.236,\ 1.906,\ 2.0,\ 2.125), variance 0.134\approx0.134
    • Round 44: h(4)(1.300, 1.451, 1.300, 1.865, 1.953, 2.016)h^{(4)} \approx (1.300,\ 1.451,\ 1.300,\ 1.865,\ 1.953,\ 2.016), variance 0.093\approx0.093

    Every node's value is crawling toward the graph's overall average. Nodes 00 and 55 started a full 1.01.0 apart; a few rounds of pure local averaging is already enough to blur that gap down to 2.0161.3000.7162.016-1.300\approx0.716.

Checkpoint

Pass rounds of messages until the variance across all six node values drops under 0.2.

01.012.020.033.041.052.0
round 0 — variance = 0.9167
Pass a round to try it
Summary
hv(k+1)=mean(hv(k),{hu(k):uN(v)})h_v^{(k+1)} = \text{mean}\Big(h_v^{(k)}, \{h_u^{(k)}: u\in\mathcal{N}(v)\}\Big)

Message passing is the graph generalization of convolution: instead of a fixed spatial window, every node aggregates whatever neighbors it actually has. But stacking too many rounds washes out exactly the local structure that made the graph interesting in the first place — real GCNs use a learned weight matrix per layer (not just a mean) and rarely go past 2-3 layers for precisely this reason. The next chapter tackles a different problem the mean rule quietly assumes away: what happens when a node has thousands of neighbors, not six?