Graph Neural Networks
A graph neural network learns on data with no grid and no canonical ordering: atoms in a molecule, users in a social network, road segments in a map. The unifying idea is message passing — each node repeatedly aggregates its neighbors' states and updates its own — built to respect the one symmetry graphs demand, permutation equivariance.
╌╌╌╌
A convolutional network
exploits one fact: an image is a grid, so every pixel has the same number of
neighbors in the same fixed positions, and one shared kernel can slide across all
of them. A molecule, a citation network, a road map has no such regularity. Nodes
have different degrees, there is no up
or left
, and relabeling the vertices
must not change the prediction. A graph neural network generalizes the
convolutional idea to this setting by replacing the fixed spatial stencil with a
node's neighborhood: each node aggregates information from the nodes it is
connected to, and reuses one shared transformation everywhere, exactly as a kernel
is reused at every position.12
Graph data
A graph fixes a set of entities and the relations between them, and attaches a feature vector to each entity.
The adjacency matrix is the algebraic handle on the structure: a single multiplication sums each node's neighbors, which is the primitive every layer below is built from. Edges may themselves carry features , and graphs may be directed or weighted, but the unweighted undirected case covers every idea below.
Three task levels
What the network predicts determines where its outputs come from.
| Level | Output | Examples |
|---|---|---|
| Node | one label per node | role in a social network, atom property |
| Edge | one label per pair | link prediction, relation type |
| Graph | one label per graph | molecule toxicity, solubility |
Node- and edge-level tasks read off the per-node representations directly; a graph-level task must first pool the node representations into a single vector, the readout step covered below.
The symmetry that defines the problem
A graph carries no node ordering. We can store its nodes in any order we like, and a permutation matrix relabels them: , . A correct model must not depend on that arbitrary choice.3
Equivariance is the right constraint for the per-node layers (a node's new state should follow it under relabeling), and invariance is the right constraint for the final graph-level readout (the molecule is the same molecule however we number its atoms). Every GNN layer below is built to be equivariant by construction, and the readout to be invariant, because the symmetry is not a nicety: a model that lacked it would have to learn the same fact times over.
The message-passing framework
Almost every GNN is one template. A layer updates each node by collecting messages from its neighbors, combining them with a permutation-invariant aggregate, then mixing the result with the node's own state through an update.4
Because takes a set and ignores order, the layer is permutation equivariant for free — the property the previous theorem demands. The aggregate is where the entire design space lives: the variants below differ only in how they weight and combine the neighbor states.
Consider the shapes. A hidden state is one vector per node; stacked over all nodes it is the matrix . The aggregate reads a variable-size set of -vectors (node contributes of them) and returns a single -vector ; a set of any size in, one fixed vector out, which is what lets one layer serve nodes of every degree. The update takes the pair through a shared weight and produces . Only the width changes across layers; the same is applied at every node, the parameter sharing that mirrors a convolutional kernel.
The algorithm is the template run for rounds. After round , a node's state depends on its -hop neighborhood, so depth controls how far information travels, the graph analogue of a receptive field.
- 1for eachinitialize with input features
- 2for to do
- 3for each node do
- 4order-invariant
- 5learnable, e.g.
- 6returnfinal node representations
Graph convolutional network (GCN)
The simplest useful instance fixes the aggregate to a normalized neighbor sum and the update to one shared linear map plus a nonlinearity. Collecting all nodes into the matrix , the GCN layer is a single propagation rule.5
Why symmetric normalization
A raw sum lets high-degree nodes dominate, since their messages add up over many neighbors and blow up the activation scale. Per node , the symmetric normalization weights the message from neighbor by :
To see where the factor comes from, start from the raw propagation and ask for the least destructive way to control its scale. Row-normalizing, , replaces the neighbor sum by a neighbor mean and fixes the scale, but it treats the message asymmetrically: the weight node puts on neighbor is , which ignores 's own degree entirely. The symmetric split takes half the normalization from each end. Reading off entry ,
for every (and off the graph), which matches the coefficient in the per-node sum above. Multiplying the propagated matrix by and applying recovers the layer definition; writing the entry out and summing over turns the matrix form into the per-node form and back. The symmetric factor keeps activation magnitudes stable across nodes of widely different degree, and discounts messages from popular neighbors (high ) that are informative about everyone and therefore about no one in particular. The choice is not arbitrary: is a first-order approximation to a spectral graph convolution, the localized filter that drops out of a Chebyshev expansion of the graph Laplacian's eigenbasis.6
A GCN layer on four nodes, by hand
One numeric pass fixes every symbol. Take a four-node graph: a triangle on nodes with a pendant node hanging off node . Its adjacency matrix, and the self-looped , are
Row-summing gives the self-looped degrees , so and . The normalized propagation matrix has entry wherever :
Give each node a scalar feature () and run the propagation. Node (self-degree , neighbors ) mixes
and doing every row gives . With a scalar weight and (the identity here, since every entry is positive), the first layer output is . Two facts read straight off the numbers: nodes and end up identical because the graph is symmetric under swapping them (permutation equivariance in action), and the isolated feature at node has bled outward from toward its neighbors, a single step of the smoothing that, iterated, becomes over-smoothing.
The two multiplications factor cleanly: is and mixes nodes (each output row is a weighted combination of input rows), while is and mixes features (each output column is a combination of input columns). Their order does not matter, , and the second grouping is cheaper when : project first, propagate the smaller matrix.
GCN is transductive as usually trained: it learns embeddings for the one fixed graph in front of it, using the full at every layer. It does not directly produce embeddings for a node it has never seen, which is the limitation the next model removes.
GraphSAGE
GraphSAGE trades GCN's whole-graph propagation for an inductive recipe that generalizes to unseen nodes and graphs. Two changes make this work: it samples a fixed-size subset of neighbors rather than using all of them, and it keeps the node and aggregated-neighbor terms separate by concatenating before projecting.7
Sampling caps the cost per node at a constant independent of degree, so a fixed GraphSAGE model runs on a billion-node graph it never saw at training time, the property that makes it inductive. The aggregator is a pluggable design choice:
| Aggregator | Definition | Notes |
|---|---|---|
| Mean | cheap; close to GCN's averaging | |
| Pool | elementwise max after a shared MLP | |
| LSTM | LSTM over a random neighbor order | most expressive, but not order-invariant |
The LSTM aggregator is the telling case: an LSTM reads a sequence, so to apply it to an orderless neighbor set GraphSAGE feeds the neighbors in a random permutation. It sacrifices strict permutation invariance for capacity, a trade the mean and pool aggregators do not make.
Graph attention network (GAT)
GCN fixes the neighbor weights by degree alone; the structural coefficient knows nothing about the features. A graph attention network learns the weights instead, scoring each neighbor by content the way self-attention scores keys, then attending only over the graph's edges.8
The shapes track the Transformer's, restricted to edges. With the projected state , the concatenation , and the attention vector , so each score is a scalar. The softmax normalizes those scalars over 's neighbors into weights summing to , and the update is their weighted sum of the -vectors , giving . The softmax runs only over 's neighbors, so attention is sparse and local (unlike a Transformer's all-pairs matrix), respecting the graph structure while letting the model decide which neighbors matter. As with the Transformer, GAT uses several attention heads in parallel and concatenates (or, at the last layer, averages) their outputs, so the network holds multiple relational patterns at once.
Readout for graph-level outputs
Node-level outputs come straight off . A graph-level prediction needs to collapse the node vectors into one, with a function that ignores their order so the answer is permutation invariant.
| Readout | Form | Keeps | Caveat |
|---|---|---|---|
| Sum | size and counts | scale grows with | |
| Mean | average profile | blind to graph size | |
| Max | (elementwise) | strongest feature | discards multiplicity |
The flat readouts throw away all coarse structure in one step. Hierarchical pooling instead coarsens the graph in stages, merging clusters of nodes into supernodes and repeating, so the readout reflects communities and motifs rather than a single global average. As the expressivity results below show, the choice of aggregator is not cosmetic: sum strictly dominates mean and max in what it can distinguish.
Expressivity: what message passing can tell apart
Message passing is expressive but provably limited. Its ceiling is a classical graph algorithm, the Weisfeiler-Lehman isomorphism test, which colors nodes by iteratively hashing the multiset of neighbor colors, exactly the shape of a GNN layer.9
The bound is tight, and reaching it requires care. A GNN matches 1-WL only when its aggregate is injective on multisets, so distinct neighbor multisets always map to distinct messages. Mean and max aggregators fail this (mean cannot tell from ; max cannot tell from when elementwise), which is why GIN uses a sum over an MLP.
Over-smoothing and over-squashing
Stacking many layers, the natural way to widen a node's receptive field, runs into two failure modes that cap practical depth.
The convergence is power iteration in disguise. Strip the learnable pieces (set and to the identity) and a GCN layer is just left-multiplication by . This matrix is symmetric with eigenvalues in , and its top eigenvalue is exactly with eigenvector (entries ). Expanding any feature column in the eigenbasis , applying layers scales component by :
because every term decays geometrically and only the component survives. Every node collapses onto the same direction , scaled only by its degree, so all feature information beyond degree is gone. The worked example already showed the first step of this: after one layer, node 's value had moved from toward its neighbors; iterate and it reaches the common limit.
The two are distinct: over-smoothing is too much mixing (everything looks the same), over-squashing is too little throughput (distant signal cannot get through a narrow cut). Residual connections, normalization, and architectural rewiring mitigate both, but they bound how deep a plain message-passing stack is useful, in sharp contrast to the hundred-layer convolutional and Transformer stacks of the earlier lessons.
Comparing the four models
The four canonical layers are one template with four aggregates.
| Model | Aggregator | Neighbor weighting | Inductive? | Attention? |
|---|---|---|---|---|
| GCN | normalized sum | fixed, | no (transductive) | no |
| GraphSAGE | mean / pool / LSTM | uniform over a sample | yes | no |
| GAT | weighted sum | learned from features | yes | yes |
| GIN | sum + MLP | uniform (with self) | yes | no |
Extending the GNN framework
GNNs postdate Goodfellow, Chollet, and Stevens, so the framework here rests on the primary literature cited in the footnotes. Two developments extend it past the four canonical layers.
- Graph Transformers. The over-smoothing and over-squashing limits both come from restricting each layer to the local neighborhood. Treat the graph as a set of tokens and let every node attend to every other — full self-attention, with the graph structure injected as a positional or structural encoding rather than a hard adjacency mask — and both pathologies ease, because information no longer has to pass through many hops. Graphormer (Ying et al., NeurIPS 2021) won the OGB large-scale-challenge with exactly this, encoding shortest-path distance and node degree as attention biases. This is the same move ViT made for images: drop the hard-coded locality prior once there is enough data and compute to learn it.
- Structural and positional encodings. A plain message-passing GNN cannot tell two nodes apart if their neighborhoods look identical (the Weisfeiler-Lehman ceiling). Adding features that break the symmetry — Laplacian eigenvectors as positional encodings, or random-walk landing probabilities — provably lifts the network above that ceiling, a graph analogue of the Transformer's positional encoding.
The applied payoff is the reason the field grew: message passing over molecular graphs underlies AlphaFold's structure module (Jumper et al., Nature 2021) and production drug-discovery and materials pipelines, where the permutation symmetry a GNN respects coincides with the symmetry a molecule has.
Takeaways
- A graph neural network generalizes convolution to irregular data by replacing the spatial stencil with a node's neighborhood and reusing one shared transformation everywhere, respecting the only symmetry graphs admit: permutation equivariance for node layers, invariance for the readout.
- Nearly every GNN is one message-passing template: , with an order-invariant aggregate that makes the layer equivariant for free.
- GCN is a normalized-adjacency propagation (a first-order spectral filter); GraphSAGE samples neighbors and concatenates to learn inductively; GAT replaces fixed weights with learned attention over edges.
- Readout (sum / mean / max, or hierarchical pooling) collapses node vectors into one graph vector for graph-level tasks; sum retains the most information.
- Message passing is capped by the Weisfeiler-Lehman test; reaching that ceiling needs an injective aggregate, which is why GIN sums over an MLP, and mean/max fall short.
- Depth is limited by over-smoothing (features collapse to a common vector) and over-squashing (exponential neighborhoods crushed through bottlenecks), so GNNs stay shallow where CNNs and Transformers go deep.
Footnotes
- Goodfellow, Deep Learning, §9.2 — Motivation: sparse interactions and parameter sharing as the levers convolution pulls; a GNN reuses the same levers with a neighborhood in place of a grid patch (GNNs postdate the 2016 text). ↩
- Scarselli, Gori, Tsoi, Hagenbuchner & Monfardini (IEEE TNN 2009), The Graph Neural Network Model — the original GNN: a contraction-map state update iterated to a fixed point over the graph. ↩
- Bronstein, Bruna, Cohen & Veličković (2021), Geometric Deep Learning: Grids, Groups, Graphs, Geodesics, and Gauges — symmetry and invariance as the organizing principle behind GNNs and convolution alike. ↩
- Gilmer, Schoenholz, Riley, Vinyals & Dahl (ICML 2017), Neural Message Passing for Quantum Chemistry — unifies GNN variants under the aggregate-then-update message-passing framework. ↩
- Kipf & Welling (ICLR 2017), Semi-Supervised Classification with Graph Convolutional Networks — the symmetric-normalized propagation as a first-order spectral convolution. ↩
- Bruna, Zaremba, Szlam & LeCun (ICLR 2014), Spectral Networks and Locally Connected Networks on Graphs — the spectral-domain origin of graph convolution via the graph Laplacian eigenbasis. ↩
- Hamilton, Ying & Leskovec (NeurIPS 2017), Inductive Representation Learning on Large Graphs — GraphSAGE: neighbor sampling and trainable aggregators for inductive embeddings on unseen nodes. ↩
- Veličković, Cucurull, Casanova, Romero, Liò & Bengio (ICLR 2018), Graph Attention Networks — masked self-attention over edges, with learned per-neighbor coefficients and multiple heads. ↩
- Xu, Hu, Leskovec & Jegelka (ICLR 2019), How Powerful are Graph Neural Networks? — the Weisfeiler-Lehman bound on message-passing expressivity and the maximally powerful GIN aggregate. ↩
╌╌ END ╌╌