Keeping it Simple: Language Models can learn Complex Molecular Distributions

Daniel Flam-Shepherd, Kevin Zhu, Alán Aspuru-Guzik

Abstract

While sophisticated graph-based models are often considered the gold standard for molecular generation, this study demonstrates that simple Recurrent Neural Networks (RNNs) using string representations—specifically SELFIES—are significantly more flexible and capable of learning complex, multi-modal, and large-scale molecular distributions. We evaluate these models across three challenging benchmarks and find that language models consistently outperform state-of-the-art graph models in distribution matching and scalability.

Introduction

In the quest to discover new drugs and materials, researchers use deep generative models to navigate "chemical space." A central debate in the field concerns the optimal representation of molecules: strings (like SMILES) or graphs. Graph-based models are mathematically elegant and respect chemical valency, but they are computationally expensive and complex to train. Conversely, string-based "language models" are simpler but have historically been criticized for "brittleness," where minor character changes lead to invalid molecules. This paper investigates whether these simpler models have been underestimated, particularly when tasked with learning distributions that are multi-modal, skewed, or involve exceptionally large molecules.

Overview of the three molecular generation tasks (a-c) and the string vs. graph representations (g) evaluated in this study.

Methods

The authors compare four primary models:

  1. SM-RNN: A standard LSTM-based RNN trained on SMILES strings.
  2. SF-RNN: An LSTM trained on SELFIES (Self-Referencing Embedded Strings), which guarantees 100% molecular validity.
  3. JTVAE (Junction Tree VAE): A graph model that assembles molecules from a fixed vocabulary of chemical substructures.
  4. CGVAE (Constrained Graph VAE): A graph model that builds molecules atom-by-atom using graph neural networks.

These models were tested on three benchmarks:

  • Penalized LogP Task: A dataset of ~160k molecules with high penalized LogP scores, testing the ability to learn "spiked" distributions.
  • Multi-distribution Task: A combination of four distinct datasets (GDB13, ZINC, CEP, and POLYMERS) creating a complex, multi-modal distribution.
  • Large Scale Task: ~300k molecules from PubChem with more than 100 heavy atoms, testing scalability to massive structures.

Results

Flexibility and Scalability

A key finding is that graph-based models are often too "stiff" for diverse tasks. For example, JTVAE's reliance on a fixed substructure vocabulary led to a vocabulary explosion (11,000 items) on the Large Scale task, rendering it untrainable. In contrast, language models treat generation as a sequence-to-sequence problem, allowing them to adapt to wildly different chemical regimes—from small drug-like molecules to massive polymers—without rigid structural assumptions.

Distribution Matching

In the Multi-distribution task, both RNN models successfully captured all four modes of the data. Graph models struggled significantly: JTVAE entirely missed the first mode, and CGVAE missed the third. Quantitatively, the SMILES and SELFIES RNNs achieved significantly lower Wasserstein distances to the training data properties (LogP, SA score, QED) than the graph models across almost every task.

Density plots for the Multi-distribution task showing that RNN models (SM-RNN, SF-RNN) closely match the training distribution across varying molecular weights, while graph models (JTVAE, CGVAE) fail to capture all modes.

Validity and Performance

The use of SELFIES effectively eliminated the "brittleness" of string representations, with the SF-RNN maintaining 100% validity across all tasks. Even on the Large Scale task, where the SMILES-based RNN's validity dropped to ~87%, the SF-RNN remained perfect. Furthermore, graph models failed completely on the Large Scale task, while RNNs successfully generated molecules with molecular weights exceeding 4000 Da.

Conclusion

This research demonstrates that simple language models, when paired with robust representations like SELFIES, are powerful tools for molecular discovery. They offer superior scalability and distribution matching compared to more complex graph-based architectures. While SMILES-based models showed some signs of memorization (lower novelty), the overall flexibility of the RNN approach suggests it is a highly viable path for exploring vast and complex chemical spaces. Future work will focus on enhancing diversity and preventing overfitting in these high-performing models.

Summary updated

BibTeX
@inproceedings{flamshepherd2022keeping,
  author = {Daniel Flam-Shepherd and Kevin Zhu and Alán Aspuru-Guzik},
  title = {{Keeping it Simple: Language Models can learn Complex Molecular Distributions}},
  booktitle = {Nature Communications},
  year = {2022},
  doi = {10.1038/s41467-022-30839-x},
}
Figure