Can Graph Neural Networks Count Substructures?

Zhengdao Chen, Lei Chen, Soledad Villar, Joan Bruna

Introduction

In domains such as computational chemistry and social network analysis, the structural "fingerprint" of a graph is often defined by the frequency of specific patterns, known as motifs or substructures. For instance, the properties of a molecule are heavily influenced by the number of benzene rings it contains. While Graph Neural Networks (GNNs) have proven effective at the Graph Isomorphism problem—distinguishing between different graphs—their ability to explicitly count these building blocks has remained a theoretical blind spot.

Extracted figure from page 5 of Can graph neural networks count substructures?

Standard GNNs typically rely on local neighborhood aggregation (Message Passing). This process can "blur" structural details, making it difficult for the network to distinguish an induced subgraph (where the absence of edges is as important as their presence) from a simple subgraph. This paper investigates the theoretical limits of popular GNN architectures in counting tasks and introduces a novel solution to surpass these boundaries.

The Theoretical "Triangle Barrier"

One of the paper's most significant findings is the identification of a "Triangle Barrier." The authors provide a formal proof that standard Message Passing Neural Networks (MPNNs) and 2nd-order Invariant Graph Networks (2-IGNs) are theoretically incapable of counting induced subgraphs consisting of three or more nodes, such as triangles.

Extracted figure from page 3 of Can graph neural networks count substructures?

While these networks can easily count "star-shaped" patterns, they struggle with cycles and paths. For path patterns, the expressive power of the network is strictly constrained by its depth; a shallow $k$-WL (Weisfeiler-Lehman) network cannot count paths exceeding a specific length threshold. The authors establish a clear hierarchy: a $k$-WL or $k$-IGN network is required to count any pattern of size $k$. This provides a theoretical roadmap for model selection based on the complexity of the target motifs.

Local Relational Pooling (LRP)

To overcome these limitations without the prohibitive cost of high-order global networks, the authors propose Local Relational Pooling (LRP). The core insight is that while global universality is expensive, most critical chemical and social motifs are local. LRP operates by:

  1. Extracting Egonets: Identifying the local neighborhood (egonet) around each node.
  2. Relational Pooling: Applying a technique that ensures permutation invariance by averaging over different node orderings within the egonet.
  3. Truncated BFS: Utilizing a $k$-truncated Breadth-First Search to limit the number of orderings, keeping the computation tractable while maintaining the power to identify local substructures.

Experimental Results

The LRP architecture was evaluated against synthetic counting tasks and established molecular benchmarks:

  • Synthetic Tasks: On triangle-counting benchmarks where standard GNNs like GCN and GIN showed high error rates (MSE 0.12–0.82), LRP achieved near-perfect accuracy with MSE as low as $10^{-8}$.
  • Molecular Benchmarks: On the ZINC dataset, a Deep LRP variant achieved a Mean Absolute Error (MAE) of 0.223, significantly outperforming the standard GIN (0.387). On QM9, LRP models consistently surpassed standard MPNNs across nearly all 12 target properties, matching the performance of much more complex "provably powerful" networks.

Conclusion

This research clarifies the relationship between GNN architecture and structural expressivity. By proving that standard message passing is insufficient for counting even simple triangles, the authors justify the need for more sophisticated local processing. Local Relational Pooling emerges as a powerful, state-of-the-art alternative that balances theoretical expressive power with computational efficiency, particularly for tasks where local motifs are the primary drivers of graph identity.

Summary updated

BibTeX
@inproceedings{chen2020can,
  author = {Zhengdao Chen and Lei Chen and Soledad Villar and Joan Bruna},
  title = {{Can Graph Neural Networks Count Substructures?}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2020},
}
Figure