Predicting a single number or a category is straightforward. Predicting a sequence, like text, is harder but well-studied. However, predicting a graph—a complex web of nodes and edges with no fixed order and varying sizes—remains a formidable challenge for standard deep learning.
In their NeurIPS 2024 paper, Any2Graph: Deep End-To-End Supervised Graph Prediction With An Optimal Transport Loss, Paul Krzakala and colleagues introduce a versatile framework designed to predict entire graphs from any input modality (images, text, or fingerprints) in a truly end-to-end fashion.
The Challenge of Supervised Graph Prediction
Supervised Graph Prediction (SGP) aims to learn a mapping from an input $X$ to a target graph $G$. This capability is essential for tasks ranging from extracting road networks from satellite imagery to identifying molecular structures from chemical fingerprints.
However, SGP faces three massive hurdles:
- Permutation Invariance: Graphs lack a canonical node ordering. Swapping the labels of two nodes leaves the graph structurally identical. Standard loss functions like Mean Squared Error fail because they penalize valid permutations.
- Variable Size: Real-world graphs vary in size. A model must determine not just the connectivity (edges) and features, but also the total number of nodes.
- Non-Euclidean Output: Graphs are discrete, combinatorial objects. Training a neural network to output them directly usually requires messy relaxations or expensive, non-differentiable decoding steps at inference time.
Existing methods often rely on task-specific heuristics (like ordering nodes by spatial position) or struggle with computational efficiency. Any2Graph aims to provide a universal, "one-size-fits-all" solution.
The Any2Graph Architecture
The Any2Graph framework is built on a modular, three-part architecture:
- Encoder: A task-specific module (e.g., a CNN for images or an MLP for fingerprints) that extracts a set of feature vectors from the input.
- Transformer: An encoder-decoder stack that converts the input features into $M$ "node embeddings," where $M$ is the maximum possible graph size.
- Graph Decoder: A series of simple Multi-Layer Perceptrons (MLPs) that process the node embeddings to predict node features, edge existence, and crucially, a masking vector indicating whether a node actually exists.
The Secret Sauce: PMFGW Loss
The core innovation of the paper is the Partially-Masked Fused Gromov-Wasserstein (PMFGW) loss. Rooted in Optimal Transport (OT) theory, PMFGW avoids forcing the model to predict nodes in a specific order. Instead, it finds the optimal structural and feature alignment between the predicted nodes and the ground-truth nodes.
The "Partially-Masked" aspect is the breakthrough: it allows the model to predict a probability for each node's existence. If the target graph has 5 nodes and the model is provisioned for up to 20, the loss encourages the model to "mask out" the extra 15 nodes. This elegantly makes the framework size-agnostic.
Key Insights and Innovations
- Learning Size via Masking: Unlike previous OT-based methods that required the output size to be known in advance, Any2Graph treats node existence as a learnable probability, allowing the model to dynamically "prune" its own output.
- Feature Diffusion (FD): For complex graphs like molecules, the authors found that training accelerates if node features are "diffused" across edges. This shifts some structural information into the linear part of the loss, smoothing the optimization landscape.
- Continuous Matching: By utilizing a continuous OT plan rather than a discrete "Hungarian matcher" (used in prior works like Relationformer), the model receives more stable gradients. This leads to better convergence, especially on heterophilic graphs where connected nodes have disparate features.
Datasets and State-of-the-Art Results
The authors evaluated Any2Graph on a diverse set of challenging benchmarks:
- Coloring (New): A synthetic task predicting adjacency and node colors from a colored Voronoi diagram.
- Sat2Graph (Toulouse & USCities): Extracting road network graphs from satellite images.
- Fingerprint2Graph (QM9 & GDB13): Reconstructing molecular structures from chemical fingerprints.
Any2Graph achieved state-of-the-art results across the board. On the Coloring dataset, it reached a Graph Isomorphism Accuracy of 85.2%, vastly outperforming the next best competitor (Relationformer at 18.14%). On the massive GDB13 dataset (featuring over 1.3 million molecules), Any2Graph significantly outperformed baselines in Graph Edit Distance and Isomorphism Accuracy, particularly when utilizing Feature Diffusion.
Furthermore, while more complex than simple regression, Any2Graph remains highly efficient at inference, capable of processing up to 10,000 graphs per second on a standard GPU.
Limitations and Future Work
The primary bottleneck for Any2Graph is scalability. The PMFGW loss has a computational complexity of $O(M^3)$, where $M$ is the maximum number of nodes. This currently limits the framework to relatively small graphs.
Future work may explore entropic regularization to parallelize the OT solver on GPUs, or the integration of low-rank OT solvers to scale the framework to much larger structures, such as social networks or large-scale protein graphs.
Summary updated