Foundations to Frontier
Tests
E. Deep Learning › E14 Graph Neural Networks

Graph pooling (DiffPool, SAGPool)

Graph classification needs one vector per graph. Global readouts (sum or mean over nodes) are simple. Hierarchical pooling instead coarsens the graph step by step, like pooling in CNNs. DiffPool (Ying and colleagues, 2018) learns a soft assignment of nodes to clusters and coarsens with A' = SᵀAS. SAGPool (Lee and colleagues, 2019) keeps the top-scoring nodes, and MinCutPool (Bianchi and colleagues, 2020) learns clusters that minimise a normalised cut. Whether pooling helps is debated: random pooling often does as well on standard benchmarks. This page covers soft and top-k pooling, coarsening and auxiliary losses. In the exercises you implement DiffPool coarsening and top-k selection, then classify graphs with 2 versus 4 communities of equal size and degree. Readouts of local features reached 0.75 accuracy, random clusters 0.56, and min-cut clusters 1.00.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Zooming out on a graph

To decide what kind of graph you have, it helps to zoom out: group tightly connected nodes into clusters, treat each cluster as one node, and look at the smaller graph. Graph pooling does this inside a neural network. Some methods learn which nodes belong together; others keep only the most important nodes. Whether zooming out helps depends on whether the answer lies in the graph’s large-scale structure. The demo shows two loosely linked groups that pooling would merge into two nodes.

Graph neural network lab
01234567891011
Feature spread across nodes: 0.7284. Repeated averaging pulls every node toward the same value, washing out the two communities (oversmoothing).
Why engineers care

Classifying whole structures (molecules, circuits, assemblies, road networks) often depends on their large-scale organisation: modules, rings, subsystems. Pooling gives models access to it.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Graph pooling produces…
  2. 2. DiffPool learns…
  3. 3. SAGPool keeps…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • DiffPool:
    • assignment S = softmax(GNN_pool(A, X)), n × k;
    • coarsened features X’ = Sᵀ Z (Z from GNN_embed) and adjacency A’ = Sᵀ A S;
    • auxiliary losses: a link loss ‖A − SSᵀ‖_F, and the entropy of each row of S (encouraging hard assignments).
  • Top-k pooling (SAGPool):
    • score each node with a GNN, keep the top ⌈ratio·n⌉ nodes and their induced subgraph, and gate features by the scores;
    • halving twice takes 100 nodes to 25.
  • MinCutPool: learn S to minimise a relaxed normalised cut, −Tr(SᵀAS)/Tr(SᵀDS), plus an orthogonality term.
  • Intra-cluster fraction:
    • Tr(A’)/sum(A’) is the share of edges inside clusters;
    • random clusters keep about 1/k of edges inside, whatever the graph.
  • Exercise 2’s graphs: 96 nodes, expected degree 8, 15% of edges between communities. The within-community probability is 0.145 for 2 communities of 48 and 0.296 for 4 of 24.
📝 Quick check (Level 1)
0/3 answered
  1. 1. DiffPool's coarsened adjacency:
  2. 2. Random assignment to 4 clusters keeps about what share of edges inside?
  3. 3. Nodes left after halving 100 twice:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Pooling in code

Exercise 1.

  • DiffPool with confident assignments coarsened two disjoint edges into a 2-node graph with self-weight 2 each.
  • The link loss vanished for a perfect clustering.
  • Top-k selection kept the two best nodes.

Practice.

  • In PyTorch Geometric, dense_diff_pool, SAGPooling, TopKPooling and dense_mincut_pool are available.
  • DiffPool’s dense S costs O(n·k) memory per graph; fine for molecules, too much for very large graphs.
  • Always compare against a strong global readout (sum or mean over GIN layers) and a random-pooling baseline.
from torch_geometric.nn import dense_diff_pool
s = gnn_pool(x, adj)                       # n x k cluster logits
z = gnn_embed(x, adj)
x2, adj2, link_loss, ent_loss = dense_diff_pool(z, adj, s)
loss = task_loss + link_loss + ent_loss
🐍 Exercise 1: coarsening
Implement DiffPool coarsening, its link loss and top-k node selection.
📝 Quick check (Level 2)
0/3 answered
  1. 1. PyG function for DiffPool:
  2. 2. DiffPool's memory cost per graph:
  3. 3. A baseline every pooling study needs:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

What pooling adds.

  • A few rounds of message passing with global readout capture local statistics (degrees, small neighbourhoods).
  • Some graph properties are mesoscale: the number and arrangement of communities, modules or rings. Pooling into clusters that follow the structure makes these explicit.
  • In the coarsened graph, the fraction of edges inside clusters directly measures modularity.

When it does not help. Mesquita, Souza and Kaski (NeurIPS 2020) found that on common benchmarks, pooling with random or complementary clusters performed about as well as learned pooling. The tasks were solvable from local features, and later GNN layers compensated for poor clusters. Pooling only pays off when the task depends on structure that the clusters capture.

Cuts and spectra. Minimising the normalised cut is NP-hard; its spectral relaxation uses the Laplacian’s smallest eigenvectors (spectral clustering). MinCutPool learns an amortised, differentiable version.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Pooling helps most when the task depends on…
  2. 2. Mesquita et al. found random pooling often…
  3. 3. The spectral relaxation of normalised cut uses…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

When does pooling help graph classification?

History.

  • R. Ying et al., “Hierarchical graph representation learning with differentiable pooling” (NeurIPS 2018).
  • J. Lee, I. Lee and J. Kang, “Self-attention graph pooling” (ICML 2019).
  • F. M. Bianchi, D. Grattarola and C. Alippi, “Spectral clustering with graph neural networks for graph pooling” (ICML 2020).
  • D. Mesquita, A. Souza and S. Kaski, “Rethinking pooling in graph neural networks” (NeurIPS 2020).

Exercise 2.

  • Task: classify random graphs with 2 versus 4 equal communities. All have 96 nodes, expected degree 8 and 15% of edges between communities, so size and degree give nothing away.
  • Data: 100 training graphs and 100 test graphs.
  • Classifier: logistic regression on features from three pipelines:
    • no pooling: readouts of two rounds of sum aggregation from constant features, namely degree statistics and neighbour-degree ratios;
    • random pooling: coarsen into k = 2 and k = 4 random clusters, then take the fraction of edges inside clusters;
    • min-cut pooling: the same, with clusters from the spectral min-cut relaxation, which MinCutPool learns to approximate.
features test accuracy
no pooling (local readouts) 0.75
random pooling 0.56
min-cut pooling 1.00
  • Structure-aware pooling solves it: after coarsening into 4 min-cut clusters, a 4-community graph keeps about 84% of its edges inside clusters. A 2-community graph split four ways keeps only about 63%, because its true communities are cut in half. One number separates the classes perfectly.
  • Random pooling is useless here: random clusters keep about 1/k of edges inside regardless of structure (near chance, 0.56).
  • Local readouts get part of the way (0.75) through indirect cues: denser communities change neighbour-degree statistics slightly.
  • Seeds: seeds 1 and 2 gave 0.75 and 0.71 (no pooling), 0.51 and 0.61 (random), and 0.99 and 1.00 (min-cut).
  • Caveat: this task was built so the answer is mesoscale. On many benchmarks, as Mesquita and colleagues found, it is not.
🐍 Exercise 2 (research): when does pooling help graph classification?
Classify 2- versus 4-community graphs using local readouts, random pooling and min-cut pooling.

Graph pooling in AI, robotics and aerospace

  • Molecules: pooling atoms into functional groups and rings for property prediction.
  • Systems engineering: coarsening component graphs into subsystems to classify designs or detect faults at the subsystem level.
  • Design lesson: pooling is worth its complexity only when the answer lives in large-scale structure; check with a random-pooling baseline.

References

  1. R. Ying et al. (2018). “Hierarchical graph representation learning with differentiable pooling.” NeurIPS.
  2. J. Lee, I. Lee and J. Kang (2019). “Self-attention graph pooling.” Proc. ICML.
  3. F. M. Bianchi, D. Grattarola and C. Alippi (2020). “Spectral clustering with graph neural networks for graph pooling.” Proc. ICML.
  4. D. Mesquita, A. Souza and S. Kaski (2020). “Rethinking pooling in graph neural networks.” NeurIPS.