Template based Graph Neural Network with Optimal Transport Distances

Cédric Vincent-Cuaz, Rémi Flamary, Marco Corneli, Titouan Vayer, Nicolas Courty · DOI

Abstract

This paper introduces the Template-based Fused Gromov-Wasserstein (TFGW) layer, a novel approach for graph representation learning. Unlike traditional Graph Neural Networks (GNNs) that rely on local message passing, TFGW represents a graph by its distances to a set of learnable "template" graphs using the Fused Gromov-Wasserstein (FGW) distance. This method explicitly captures both topological and feature-based similarities, allowing the model to distinguish structures that are often indistinguishable by the Weisfeiler-Lehman (WL) test. We demonstrate that TFGW achieves state-of-the-art results on several graph classification benchmarks, particularly on datasets where structural information is paramount.

Introduction

Most modern GNNs follow the message-passing paradigm, where node features are iteratively aggregated from neighbors. While effective, this approach is fundamentally limited by the WL-test, making it difficult for models to distinguish certain non-isomorphic graphs, such as those containing different cycle types. Furthermore, structural information is often only implicitly captured through these aggregations.

To address these limitations, we propose a distance-based perspective. By defining a robust metric between attributed graphs, any graph can be represented by its "coordinates" relative to a set of reference prototypes or templates. This paper introduces the TFGW layer, which utilizes Optimal Transport to compute these distances in an end-to-end learnable framework.

The TFGW Layer and FGW Metric

The core of our method is the TFGW layer, which computes the Fused Gromov-Wasserstein (FGW) distance between an input graph and $K$ learnable template graphs.

Fused Gromov-Wasserstein Distance

FGW is an Optimal Transport metric designed for attributed graphs. It finds a soft matching (coupling) between nodes that minimizes a trade-off between two components:

  1. Feature Dissimilarity: The Wasserstein component, measuring differences in node attributes.
  2. Structural Dissimilarity: The Gromov-Wasserstein component, measuring differences in the relationships (topology) between pairs of nodes.

Model Architecture

The TFGW layer outputs a $K$-dimensional vector, where each entry is the FGW distance to one of the $K$ templates. This vector serves as a global representation of the input graph, which can then be fed into a standard classifier like a Multi-Layer Perceptron (MLP).

Architecture of the TFGW layer, showing the computation of distances to learnable template graphs and the subsequent classification.

Crucially, the templates—including their structure, features, and node weights—are learned via backpropagation. We utilize the Envelope Theorem to differentiate through the FGW solver, allowing for efficient gradient computation without unrolling the optimization loop.

Experimental Evaluation

We evaluated TFGW on both synthetic and real-world benchmarks to test its ability to capture complex structural patterns.

Synthetic Benchmarks

On datasets designed to challenge the WL-test, such as 4-CYCLES and SKIP-CIRCLES, TFGW achieved near-perfect accuracy (0.99 and 1.00, respectively). In contrast, standard GNNs like GIN failed significantly (0.50 and 0.10), as their local filters cannot distinguish these global structural differences.

Real-World Performance

TFGW consistently matched or outperformed state-of-the-art models across various domains:

  • Social Networks: On the IMDB-B dataset, TFGW reached 78.3% accuracy, a substantial improvement over previous GNNs (66.3%) and kernel methods (71.6%).
  • Bioinformatics: The model showed competitive performance on datasets like MUTAG, PTC, and PROTEINS.

Analysis and Insights

Visualization of the embedding space reveals that learned templates do not simply represent "average" graphs. Instead, they evolve into "extreme" prototypes that reside at the edges of the data manifold, effectively maximizing the margin between different classes.

PCA visualization of the FGW embedding space for the PTC dataset. The plots show how samples cluster and how templates (squares) are positioned relative to the data distribution under different GNN configurations.

Furthermore, the TFGW representation is theoretically invariant to strong isomorphism, ensuring that node permutations do not alter the output vector. The model also supports "node selection" within templates by learning sparse node weights on the probability simplex.

Conclusion and Future Work

TFGW offers a powerful alternative to message-passing GNNs by explicitly modeling graph distances. While it provides significant gains in accuracy and interpretability, the quadratic/cubic complexity of the FGW distance calculation remains a challenge for very large graphs. Future work will focus on accelerating these computations using GPU-based solvers and extending the framework to tasks like subgraph detection.

Summary updated

BibTeX
@inproceedings{vincentcuaz2022template,
  author = {Cédric Vincent-Cuaz and Rémi Flamary and Marco Corneli and Titouan Vayer and Nicolas Courty},
  title = {{Template based Graph Neural Network with Optimal Transport Distances}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=seYcx6CqPe},
}
Figure