Overcoming Order in Autoregressive Graph Generation for Molecule Generation

Edo Cohen-Karlik, Eyal Rozenberg, Daniel Freedman

Abstract

Graph generation is a fundamental problem in various domains, and is of particular interest in chemistry where graphs may be used to represent molecules. Recent work has shown that molecular graph generation using recurrent neural networks (RNNs) is advantageous compared to traditional generative approaches which require converting continuous latent representations into graphs. One issue which arises when treating graph generation as sequential generation is the arbitrary order of the sequence which results from a particular choice of graph flattening method: in the chemistry setting, molecular graphs commonly have multiple SMILES strings corresponding to the same molecule. Inspired by the use case of molecular graph generation, we propose using RNNs, taking into account the non-sequential nature of graphs by adding an Orderless Regularization (OLR) term that encourages the hidden state of the recurrent model to be invariant to different valid orderings present under the training distribution. We demonstrate that sequential molecular graph generation models benefit from our proposed regularization scheme, especially when data is scarce. Our findings contribute to the growing body of research on graph generation and provide a valuable tool for various applications requiring the synthesis of realistic and diverse graph structures.

Introduction

In drug discovery and materials science, molecules are naturally represented as graphs where atoms serve as nodes and chemical bonds as edges. To leverage the powerful sequence-generation capabilities of recurrent neural networks (RNNs)—architectures originally designed for Natural Language Processing—these 2D graph structures must be "flattened" into 1D strings. Common methods include SMILES strings or trajectories derived from Depth-First Search (DFS) traversals.

However, this flattening process introduces a fundamental contradiction: while a sequence has a strict order, a molecular graph does not. A single molecule can be represented by numerous equally valid sequences depending on the starting atom and the traversal path chosen. This "one-to-many" mapping problem forces models to learn that disparate sequences actually describe identical chemical structures. Without specific guidance, models often require massive datasets to overcome this representational noise and learn the underlying rules of chemistry.

Methodology: Orderless Regularization (OLR)

To address the order-dependency of autoregressive models, we introduce Orderless Regularization (OLR). This technique is designed to bake "order-invariance" directly into the model’s inductive bias.

Hidden State Invariance

The core principle of OLR is that if two different sequences represent the same subgraph and terminate at the same node, the model's internal memory—its hidden state—should be nearly identical. By enforcing this invariance, the model learns to focus on the structural properties of the graph rather than the arbitrary sequence of its construction.

Figure 4: Illustration of two distinct Depth-First Search (DFS) trajectories for the same graph structure. OLR encourages the model to produce similar hidden states for such varied orderings to ensure the model learns the underlying graph structure rather than just the sequence.

The OLR Loss Term

During training, we add an auxiliary loss function that penalizes the model if the hidden states produced by two different DFS trajectories of the same graph are far apart in the latent space. This forces the model to cluster different orderings of the same molecule together, effectively learning the "concept" of the molecule.

Efficient Trajectory Sampling

Since finding all possible traversals is computationally expensive (NP-complete), we utilize an efficient heuristic algorithm to generate distinct DFS trajectories. This approach specifically targets "1-edge" and "2-edge" connected graphs, which encompass over 99% of molecules in standard datasets like ZINC, making OLR computationally practical for real-world applications.

Experimental Evaluation

We evaluated OLR across two primary tasks to test its efficacy in both synthetic and realistic chemical settings.

  1. Wiener Index Prediction: This synthetic task required the model to predict a topological metric (the sum of distances between all node pairs). To simulate extreme data scarcity, the model was trained on only 50 examples. OLR improved prediction accuracy from 0.18 to 0.28 and nearly halved the Mean Absolute Error (MAE) compared to a standard LSTM.
  2. MOSES Benchmark: Using a subset of 1,000 molecules from the ZINC-based MOSES dataset, we tested molecular generation. OLR-enhanced models (LSTM and GRU) consistently outperformed baselines. In terms of Rank Average—a composite score of validity, uniqueness, and diversity—OLR achieved a score of 1.57, significantly better than models trained on Canonical (2.28) or Randomized (2.07) SMILES.

Key Insights and Discussion

Our results highlight that OLR provides a significant "small data" advantage. By providing a shortcut for the model to understand graph structures, OLR reduces the need for brute-force memorization. t-SNE visualizations confirmed this, showing that OLR-trained models naturally cluster different orderings of the same molecule, whereas vanilla models produce scattered representations.

Furthermore, OLR-enhanced models showed superior performance in Fréchet ChemNet Distance (FCD), indicating that the generated molecules were chemically much closer to the real-world distribution of the training set than those produced by standard models.

Limitations and Future Work

While OLR proved highly effective for RNNs, it did not yield similar improvements for Transformer architectures. We hypothesize this is due to the Transformer's heavy reliance on positional encodings, which are inherently tied to sequence order. Future research will focus on developing "graph-aware" positional encodings to bring the benefits of order-invariance to attention-based models. Additionally, while our current sampling heuristic covers most molecules, further optimization may be needed for highly complex, large-scale heterogeneous graphs.

Summary updated

BibTeX
@article{cohenkarlik2024overcoming,
  author = {Edo Cohen-Karlik and Eyal Rozenberg and Daniel Freedman},
  title = {{Overcoming Order in Autoregressive Graph Generation for Molecule Generation}},
  journal = {Accepted by TMLR},
  year = {2024},
  url = {https://openreview.net/forum?id=BK6Gc10tRy},
}
Figure