Graph Neural Networks Can (Often) Count Substructures
Paolo Pellizzoni, Till Hendrik Schulz, Karsten M. Borgwardt
Abstract
Message passing graph neural networks (GNNs) are known to have limited expressive power in their ability to distinguish some non-isomorphic graphs. Because of this, it is well known that they are unable to detect or count arbitrary graph substructures (i.e., solving the subgraph isomorphism problem), a task that is of great importance for several types of graph-structured data. However, we observe that GNNs are in fact able to count graph patterns quite accurately across several real-world graph datasets. Motivated by this observation, we provide an analysis of the subgraph-counting capabilities of GNNs beyond the worst case, deriving several sufficient conditions for GNNs to be able to count subgraphs and, more importantly, to be able to sample-efficiently learn to count subgraphs. Moreover, we develop novel dynamic programming algorithms for solving the subgraph isomorphism problem on restricted classes of pattern and target graphs, and show that message-passing GNNs can efficiently simulate these dynamic programs. Finally, we empirically validate that our sufficient conditions for GNNs to count subgraphs hold on many real-world datasets, providing a theoretically-grounded explanation to our motivating observations.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 706afca4-581e-4a64-b756-eb6c78a62be5Cited by top-tier papers4
- What Expressivity Theory Misses: Message Passing Complexity for GNNsNiklas Kemper, Tom Wollschläger, Stephan GünnemannNeurIPS 2025 · 3 citations
- Which Algorithms Can Graph Neural Networks Learn?Solveig Wittig, Antonis Vasileiou, Robert R. Nerem, Timo Stoll et al.ICML 2026
- Learning the Neighborhood: Contrast-Free Multimodal Self-Supervised Molecular Graph PretrainingBoshra Ariguib, Mathias Niepert, Andrei ManolacheICML 2026
- Gelato: Graph Edit Distance via Autoregressive Neural Combinatorial OptimizationPaolo Pellizzoni, Till Hendrik Schulz, Karsten M. BorgwardtICLR 2026
Builds on16
- Open Graph Benchmark: Datasets for Machine Learning on GraphsWeihua Hu, Matthias Fey, Marinka Zitnik, Yuxiao Dong et al.NeurIPS 2020 · 3,935 citations
- Can Graph Neural Networks Count Substructures?Zhengdao Chen, Lei Chen, Soledad Villar, Joan BrunaNeurIPS 2020 · 392 citations
- What Can Neural Networks Reason About?Keyulu Xu, Jingling Li, Mozhi Zhang, Simon S. Du et al.ICLR 2020 · 281 citations
- Equivariant Subgraph Aggregation NetworksBeatrice Bevilacqua, Fabrizio Frasca, Derek Lim, Balasubramaniam Srinivasan et al.ICLR 2022 · 217 citations
- Understanding and Extending Subgraph GNNs by Rethinking Their SymmetriesFabrizio Frasca, Beatrice Bevilacqua, Michael M. Bronstein, Haggai MaronNeurIPS 2022 · 168 citations
Related papers
- Learning to Count Isomorphisms with Graph Neural NetworksXingtong Yu, Zemin Liu, Yuan Fang, Xinming ZhangAAAI 2023 · 24 citations
- Graph Convolutional Networks with Dual Message Passing for Subgraph Isomorphism Counting and MatchingXin Liu, Yangqiu SongAAAI 2022 · 37 citations
- Distance-Restricted Folklore Weisfeiler-Leman GNNs with Provable Cycle Counting PowerJunru Zhou, Jiarui Feng, Xiyuan Wang, Muhan ZhangNeurIPS 2023 · 15 citations
- Homomorphism Counts for Graph Neural Networks: All About That BasisEmily Jin, Michael M. Bronstein, Ismail Ilkan Ceylan, Matthias LanzingerICML 2024 · 23 citations
- Counting Graph Substructures with Graph Neural NetworksCharilaos I. Kanatsoulis, Alejandro RibeiroICLR 2024 · 17 citations
