NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Fast subtree kernels on graphs

Nino Shervashidze, Karsten M. BorgwardtNeurIPS 2009

Overview

This paper introduces a highly efficient graph kernel based on the Weisfeiler-Lehman (WL) test of isomorphism. By leveraging the WL relabeling process, the authors developed a subtree kernel that scales linearly with the number of edges ($O(mh)$). This breakthrough allows the kernel to process graphs with thousands of nodes in mere minutes—tasks that previously took days or were computationally impossible.

The Scalability Bottleneck in Graph Kernels

Graph kernels are essential tools for measuring the similarity between structured data, such as molecules or protein networks. However, traditional "subtree" kernels—which compare the local neighborhood structures around nodes—have historically suffered from massive scalability bottlenecks.

The classic Ramon-Gärtner subtree kernel, for instance, has a runtime complexity that is exponential in the maximum degree of the graph ($O(n^2 4^d h)$). This made it practically unusable for graphs with more than about 100 nodes. While other kernels based on random walks or paths existed, they often struggled with labeled graphs or lacked the expressive power of subtree patterns. The authors sought to bridge this gap by creating a kernel that is both highly expressive (subtree-based) and efficient enough for large-scale, labeled graph datasets.

Methods: The Weisfeiler-Lehman Kernel

The core innovation of this paper is the adaptation of the 1-dimensional Weisfeiler-Lehman (WL) test from graph theory into a machine learning kernel framework.

The WL test is an iterative process traditionally used to check if two graphs are isomorphic (identical in structure). In each iteration $h$:

  1. Multiset-labeling: Each node receives a label based on the labels of its immediate neighbors.
  2. Sorting & Concatenation: These neighbor labels are sorted and combined with the node's own label into a string.
  3. Compression: These strings are hashed (compressed) into new, shorter labels.
  4. Relabeling: The nodes are updated with these new compressed labels.

The key insight is that these compressed labels act as unique identifiers for specific subtree patterns of height $h$. By simply counting how many times each label appears in two different graphs and taking the dot product of these count vectors, one obtains a valid, highly expressive kernel.

The authors propose two computational versions:

  • Pairwise WL: Comparing two graphs at a time.
  • Global WL: Processing all $N$ graphs in a dataset simultaneously using a shared hash map. This further optimizes the runtime to $O(Nhm + N^2hn)$.

Key Insights

  • Isomorphism Tests as Feature Extractors: The paper brilliantly recognizes that an algorithm designed to distinguish graphs (the WL test) is perfectly suited to describe them for machine learning.
  • Linear Scaling: By replacing expensive matching algorithms with a simple sorting and hashing scheme, the complexity drops from exponential to linear with respect to the number of edges ($m$).
  • The Power of Labels: Unlike many previous "fast" kernels that only worked well on unlabeled graphs, the WL kernel naturally incorporates node labels, which are crucial for chemical and biological data.
  • Subtree Patterns vs. Strict Subtrees: The kernel counts "subtree patterns" (which allow for repeated nodes, like tree-walks). This is computationally much easier than counting strict subgraphs while remaining highly informative.

Datasets and Results

The authors evaluated their kernel on four standard bio- and chemo-informatics benchmarks:

  • MUTAG: 188 mutagenic aromatic and heteroaromatic nitro compounds.
  • NCI1 & NCI109: Two large datasets (over 4,000 graphs each) representing chemical compounds screened for anti-cancer activity.
  • D&D: A dataset of 1,178 protein structures (classified as enzymes or non-enzymes). This is the "large" dataset, with some graphs containing thousands of nodes.

Massive Speedup and Accuracy

On the D&D protein dataset, the WL kernel computed subtree patterns of height 10 in just 11 minutes. In stark contrast, the Shortest Path kernel took over 23 hours, and the Ramon-Gärtner kernel couldn't finish even a small subsample within two days. Furthermore, the WL kernel achieved the highest accuracy on three out of the four datasets. Notably, on the NCI datasets, it improved accuracy by more than 8% over previous state-of-the-art methods.

Scalability

Experimental results on synthetic graphs confirmed that the "Global WL" approach scales linearly, making it a viable choice for large-scale graph mining.

Runtime comparison of pairwise vs. global WL kernels across different graph parameters.

As illustrated above, the global computation method vastly outperforms the pairwise approach across multiple dimensions, maintaining low runtime growth as the number of graphs ($N$), graph size ($n$), subtree height ($h$), and graph density ($c$) increase.

Limitations and Future Work

While highly effective, the proposed method has a few limitations:

  • Discrete Labels Only: The current algorithm relies on discrete node labels (like atom types). It does not natively handle continuous attributes (like 3D coordinates) or high-dimensional vectors.
  • Structural Resolution: While the 1D-WL test is powerful, there are known non-isomorphic graphs that it cannot distinguish. Higher-dimensional WL tests could be explored, though they would incur higher computational costs.
  • Edge Labels: Extending the method to edge labels is straightforward, but it was not the primary focus of the experimental results in this specific paper.

Summary updated

BibTeX
@inproceedings{shervashidze2009fast,
  author = {Nino Shervashidze and Karsten M. Borgwardt},
  title = {{Fast subtree kernels on graphs}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2009},
}
Figure