G$^2$N$^2$ : Weisfeiler and Lehman go grammatical

Jason Piquenot, Aldo Moscatelli, Maxime Berar, Pierre Héroux, Romain Raveaux, Jean-Yves Ramel, Sébastien Adam

Overview

The authors introduce $G^2N^2$ (Grammatical Graph Neural Network), a novel framework that systematically translates algebraic matrix languages into provably expressive Graph Neural Network (GNN) architectures using Context-Free Grammars (CFGs). By applying a grammar reduction scheme, they derive a model that is as powerful as the 3-Weisfeiler-Lehman (3-WL) isomorphism test but significantly more efficient and performant than existing high-order GNNs.

The Expressivity Bottleneck in GNNs

Standard Message Passing Neural Networks (MPNNs) are fundamentally limited in their "expressive power"—their ability to distinguish between different graph structures. Formally, they are no more powerful than the 1-Weisfeiler-Lehman (1-WL) isomorphism test, meaning they fail to distinguish even simple non-isomorphic graphs, such as certain circular structures.

To overcome this limitation, researchers have looked toward the 3-WL test as a benchmark for higher expressiveness. While models like 3-IGN or PPGN reach this theoretical limit, they often suffer from massive computational overhead due to the use of high-order tensors. Furthermore, they lack a formal, systematic link to the algebraic languages that define these expressiveness levels. There has long been a bottleneck in turning theoretical algebraic fragments (like MATLANG) into practical, efficient neural layers.

Methods: Architecture as a Formal Language

The core innovation of this paper is treating GNN architecture design as a formal language problem. This moves away from "trial and error" architecture design toward a "correct-by-construction" approach for expressiveness.

The G$^2$N$^2$ pipeline: translating an algebraic language fragment into a reduced Context-Free Grammar, and finally into a neural layer.
  1. MATLANG & CFGs: The authors start with MATLANG, a matrix language known to characterize WL expressiveness. They represent a fragment of this language ($\mathcal{L}_3$, which corresponds to 3-WL) as a Context-Free Grammar (CFG)—a set of generative rules that can produce any valid algebraic sentence in that fragment.
  2. Grammar Reduction: Raw grammars derived directly from a language are often redundant. The authors propose a reduction scheme to eliminate unnecessary operations (like certain transposes or redundant multiplications) while mathematically proving that the expressive power remains intact. This reduction is not just theoretical; it halves the number of parameters required in practice.
  3. The $G^2N^2$ Layer: They translate the rules of the reduced grammar directly into a GNN layer. Because the architecture is a direct instantiation of the $\mathcal{L}_3$ grammar, it is provably as expressive as the 3-WL test.

Inside the $G^2N^2$ Layer

Iterative execution within the G$^2$N$^2$ layer, detailing rule selection, input selection, computation, and output storage.

The layer operates iteratively, maintaining "memories" (tensors) for matrices and vectors. During each iteration, learnable linear blocks and Multi-Layer Perceptrons (MLPs) act as a selection mechanism. They decide which algebraic operations (e.g., Hadamard products, matrix multiplications) to apply to the stored variables, computing new representations and storing them for the next step.

Key Results and Performance

The model was evaluated on several standard benchmarks, demonstrating that 3-WL power does not strictly require the brute-force complexity of 3rd-order tensors.

  • State-of-the-Art on QM9: On this large-scale dataset of 130k molecules, $G^2N^2$ outperformed the previous 3-WL leader, PPGN, on almost all 12 regression targets. Notably, it achieved this while being faster to train (e.g., 98s per epoch vs. 129s for PPGN).
  • Superior Classification on TUD: Across the TU Datasets (MUTAG, PTC, Proteins, NCI1, and IMDB), $G^2N^2$ ranked 1st or 2nd among all GNN competitors in five out of six tasks, showing robust generalization.
  • Spectral Versatility: Most GNNs naturally act as low-pass filters. In synthetic spectral tests, $G^2N^2$ successfully learned band-pass filters where other powerful models like PPGN failed, matching the performance of specialized spectral models like CHEBNET. This proves $G^2N^2$ is uniquely capable of approximating any continuous filter.

Limitations and Future Work

While the framework is generic, the current instantiation is specifically tailored for 3-WL. Scaling to $k$-WL for $k > 3$ would require the framework to handle higher-order tensors, reintroducing the computational scaling issues the authors originally sought to avoid.

Additionally, the authors suggest that the weights learned by the "rule selection" MLPs could be used for informed pruning—automatically removing algebraic operations that aren't useful for a specific task. While promising, a fully automated version of this pruning has yet to be implemented. Future work could also involve applying this grammatical approach to other types of languages beyond MATLANG to bake different structural priors into GNNs.

Summary updated

BibTeX
@inproceedings{piquenot2024g,
  author = {Jason Piquenot and Aldo Moscatelli and Maxime Berar and Pierre Héroux and Romain Raveaux and Jean-Yves RAMEL and Sébastien Adam},
  title = {{G$^2$N$^2$ : Weisfeiler and Lehman go grammatical}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=eZneJ55mRO},
}
Figure