Learning to generate feasible graphs using graph grammars

Stefan Mautner, Rolf Backofen, Fabrizio CostaarXiv 2025

TL;DR

Standard deep learning models often fail to generate structurally valid graphs because long-range dependencies get "diluted" across message-passing layers. This paper introduces a graph grammar approach combined with a domain-specific coarsening procedure that simplifies graphs into higher-level structures, enabling the generation of 100% feasible molecules and complex, large-scale RNA structures.

What Problem Does This Paper Address?

Generating realistic graphs—such as molecular structures for drug discovery or RNA sequences—is exceptionally challenging. A valid graph must satisfy both local constraints (like atomic valency) and long-range dependencies (like avoiding oversized rings or ensuring proper RNA folding).

Currently, most graph generation relies on deep neural networks using message-passing schemes. However, these architectures suffer from information dilution: as information travels across a large graph, the signal degrades, making it incredibly difficult for the model to enforce global structural integrity. As a result, deep learning models frequently generate invalid, unstable, or fragmented structures when scaled up to larger graphs.

Methods

The authors address this by building on a Markov Chain Monte Carlo (MCMC) sampling framework that uses context-sensitive graph grammars to propose structural mutations. To solve the long-range dependency problem, they introduce two key innovations:

  1. Grammar Coarsening: Instead of operating purely at the level of individual nodes (atoms or nucleotides), the graph is simplified into a coarser representation using edge or vertex contraction based on domain knowledge. For example, individual RNA nucleotides are grouped into structural components like stems and loops. Graph grammar rules—defined as Core-Interface Pairs (CIPs)—are then extracted and applied at this coarser scale, effectively turning long-range global dependencies into local ones.
  2. Constraint Integration: To guarantee physical viability, the framework allows users to integrate domain-specific optimization algorithms directly into the generation pipeline. For RNA generation, candidate graphs have their pairwise nucleotide bonds stripped and recomputed using a thermodynamic folding algorithm (RNAalifold), ensuring the final output is always a stable, viable structure.
Core and interface subgraphs at different resolutions

Datasets

The approach was evaluated on two distinct domains:

  • MOSES (Molecular Sets): A standard benchmark suite containing clean, small organic molecules used to evaluate molecular generation qualities like drug-likeness, synthesizability, and internal diversity.
  • Rfam Database: The authors selected complex RNA families RF01725 (SAM-I/IV variant riboswitch) and RF00162 (SAM riboswitch) to test the model's ability to generate large graphs (hundreds of nodes) with intricate secondary structures.

Key Insights and Ideas

  • Scale Shifting Solves Dilution: By shifting the grammar's operations from individual nodes to higher-level structural motifs (like rings or stems), long-range constraints naturally become local constraints, bypassing the information dilution bottleneck entirely.
  • Grammars vs. Autoregressive Violations: Purely deep autoregressive models (like GraphRNN) frequently violate basic topological rules, such as breaking the continuous ribose backbone of an RNA molecule. Graph grammars inherently preserve these structural invariants.
  • The Sampling Paradox: Without coarsening, expanding the training set can actually decrease generation quality. A larger dataset yields a massive, overly permissive grammar that easily generates unstable structures. Coarsening keeps the structural context tight and effective regardless of dataset size.

Key Results

  • 100% Molecular Validity: On the MOSES benchmark, the proposed method achieved a perfect 1.0 validity score, drastically outperforming popular deep learning baselines like VAE (0.001) and ORGAN (0.108).
  • Biologically Viable RNA: The generated RNA sequences successfully passed the stringent verification thresholds of the Infernal covariance model (a state-of-the-art RNA classifier), proving they are functionally equivalent to real biological families.
  • Maintained Backbones: While baseline models like GraphRNN generated disconnected components or invalid cycles, the grammar approach consistently maintained a continuous, realistic RNA backbone.
Figure 3: Examples of the rf01725 family of RNA, exhibiting a large variety of structural configurations.

Limitations and Future Work

The primary limitation of this method is its reliance on predefined, domain-specific coarsening rules. A human expert must still manually define how the graph should be simplified (e.g., identifying what constitutes a molecular ring or an RNA stem).

To make the system truly domain-agnostic, the authors point to an exciting future direction: leveraging machine learning to automatically learn optimal graph coarsening procedures directly from raw data.

Summary updated

Abstract

Generative methods for graphs need to be sufficiently flexible to model complex dependencies between sets of nodes. At the same time, the generated graphs need to satisfy domain-dependent feasibility conditions, that is, they should not violate certain constraints that would make their interpretation impossible within the given application domain (e.g. a molecular graph where an atom has a very large number of chemical bounds). Crucially, constraints can involve not only local but also long-range dependencies: for example, the maximal length of a cycle can be bounded. Currently, a large class of generative approaches for graphs, such as methods based on artificial neural networks, is based on message passing schemes. These approaches suffer from information 'dilution' issues that severely limit the maximal range of the dependencies that can be modeled. To address this problem, we propose a generative approach based on the notion of graph grammars. The key novel idea is to introduce a domain-dependent coarsening procedure to provide short-cuts for long-range dependencies. We show the effectiveness of our proposal in two domains: 1) small drugs and 2) RNA secondary structures. In the first case, we compare the quality of the generated molecular graphs via the Molecular Sets (MOSES) benchmark suite, which evaluates the distance between generated and real molecules, their lipophilicity, synthesizability, and drug-likeness. In the second case, we show that the approach can generate very large graphs (with hundreds of nodes) that are accepted as valid examples for a desired RNA family by the "Infernal" covariance model, a state-of-the-art RNA classifier. Our implementation is available on github: github.com/fabriziocosta/GraphLearn
BibTeX
@misc{mautner2025learning,
  author = {Stefan Mautner and Rolf Backofen and Fabrizio Costa},
  title = {{Learning to generate feasible graphs using graph grammars}},
  year = {2025},
  eprint = {2501.06003},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.06003},
}

Loading related content...

Figure