Summary
A graph neural network (GNN) updates each node’s features by aggregating its neighbors’ features and applying a learned transformation. The simplest variant is one matmul: , where is a normalized adjacency matrix and stacks node features.
A CNN exploits regular grid structure with shared local filters. A GNN applies shared parameters and local aggregation to neighborhoods defined by graph edges. This supports models for social networks, molecules, knowledge graphs, code ASTs, and recommender bipartite graphs.
GNNs power drug-discovery pipelines (AlphaFold’s Evoformer, DeepMind’s GNoME), large-scale recommenders (Pinterest’s PinSAGE, Uber’s GraphSAGE), and protein structure prediction. Modern transformers are arguably a special case (complete graph with attention as edge weighting).
The mechanism: GCN
The graph convolutional network (Kipf & Welling, 2017) is the canonical GNN:
where is the symmetrically normalized adjacency with self-loops.
Decompose:
- Aggregate: forms a degree-normalized weighted sum of each node’s neighbors and itself (via the self-loop).
- Transform: multiply by to mix features.
- Activate: ReLU or similar.
After layers, each node has aggregated information from its -hop neighborhood. The network is a sequence of matmuls, the same operation as any other deep learning model. The graph structure shows up only in .
Learning objective
Connect one node's neighborhood to one row of A-hat H W.
Variants by aggregator
- GraphSAGE (Hamilton et al., 2017). Sample a fixed number of neighbors per node; aggregate with mean, max, or LSTM. Practical for large graphs where full-neighbor aggregation is infeasible.
- GAT (Veličković et al., 2018). Replace uniform averaging with learned attention weights per edge: . Same form as transformer attention, restricted to graph neighbors.
- GIN (Xu et al., 2019). Use sum aggregation and a learnable epsilon. Provably as expressive as the Weisfeiler-Lehman graph isomorphism test.
- Message-passing neural networks (Gilmer et al., 2017). General framework: edges carry messages, nodes aggregate, both can be parametrized.
What the message-passing framework looks like
Most GNNs fit:
Aggregate is permutation-invariant (sum, mean, max, attention). Different choices give different GNN families.
Where GNNs hit walls
- Over-smoothing. After many layers, all nodes converge to similar representations. Practical depth: 2 to 5 layers for most graphs. Workarounds: residual connections, gating, jumping-knowledge networks.
- Over-squashing. Information from distant nodes gets compressed through narrow bottlenecks. Long-range dependencies are hard.
- Scalability. Full-graph training is per layer; sampling (GraphSAGE) or graph clustering (Cluster-GCN) is needed for large graphs.
- Expressiveness. Standard GNNs cannot distinguish graphs that the Weisfeiler-Lehman test cannot distinguish. More expressive variants (k-GNN, subgraph GNN) are slower.
Transformers as graphs
A standard transformer is a GNN on the complete graph with attention as the edge function. This is why graph transformers (Graphormer, GraphGPS) work: take a transformer, restrict the attention pattern to edges (or weight by graph distance), get a GNN with strong expressiveness.
Common pitfalls
- Treating GNNs as deep. They go shallow (2 to 5 layers) for over-smoothing reasons.
- Forgetting self-loops. Without them, a node loses its own features after one aggregation step.
- Using sum without normalization on heterogeneous-degree graphs. High-degree nodes dominate; normalize by degree or use mean/attention.
- Reporting accuracy without specifying the data split. Transductive vs inductive performance differ dramatically; many papers fudge this.