Language models can learn complex molecular distributions

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

Abstract

Deep generative models of molecules have grown immensely in popularity, trained on relevant datasets, these models are used to search through chemical space. The downstream utility of generative models for the inverse design of novel functional compounds, depends on their ability to learn a training distribution of molecules. The most simple example is a language model that takes the form of a recurrent neural network and generates molecules using a string representation. Since their initial use, subsequent work has shown that language models are very capable, in particular, recent research has demonstrated their utility in the low data regime. In this work, we investigate the capacity of simple language models to learn more complex distributions of molecules. For this purpose, we introduce several challenging generative modeling tasks by compiling larger, more complex distributions of molecules and we evaluate the ability of language models on each task. The results demonstrate that language models are powerful generative models, capable of adeptly learning complex molecular distributions. Language models can accurately generate: distributions of the highest scoring penalized LogP molecules in ZINC15, multi-modal molecular distributions as well as the largest molecules in PubChem. The results highlight the limitations of some of the most popular and recent graph generative models- many of which cannot scale to these molecular distributions.

Introduction

The search for novel functional compounds in chemical space relies heavily on deep generative models. While recent trends in AI-driven drug discovery have favored complex graph-based architectures—viewing molecules as nodes and edges to align with chemical intuition—these models often encounter a "complexity wall." They struggle with very large molecules or datasets containing highly diverse chemical types. This study, published in Nature Communications, investigates whether simpler language models, such as Recurrent Neural Networks (RNNs) that treat molecules as character sequences, possess the latent capacity to outperform graph-based counterparts in learning complex, multi-modal, and large-scale molecular distributions.

Methodology

The researchers compared simple RNNs using Long Short-Term Memory (LSTM) units against two prominent graph-based baselines: the Junction Tree VAE (JTVAE) and the Constrained Graph VAE (CGVAE). The language models utilized two string representations: the industry-standard SMILES and the robust SELFIES. To evaluate how well these models captured the underlying training distributions, the authors employed the Wasserstein distance to compare physical property distributions (e.g., molecular weight, solubility) between generated and training sets.

Experimental Tasks

Three challenging generative tasks were designed to test model limits:

  1. Penalized LogP Task: Capturing the "spiked" distribution of ~160,000 high-scoring molecules from ZINC15.
  2. Multi-distribution Task: Learning a mixture of four distinct datasets (GDB13, ZINC, CEP, and POLYMERS) simultaneously.
  3. Large-scale Task: Generating ~300,000 of the largest molecules in PubChem (over 100 heavy atoms).
Density plots showing the molecular weight distributions for the multi-distribution and large-scale tasks.

Results and Discussion

The results demonstrate that language models are remarkably adept at learning complex distributions where graph models falter.

Distribution Matching and Scaling

In the LogP task, SMILES-based RNNs achieved a Wasserstein distance nearly six times better than JTVAE, effectively capturing the subtle high-scoring "tail" that graph models tended to ignore. In the multi-distribution task, RNNs successfully learned all four modes, whereas graph models often missed entire categories; for instance, JTVAE failed on small GDB13 molecules and CGVAE missed the CEP mode.

Representative chemical structures from the GDB 13, ZINC, CEP, and POLYMERS datasets, alongside a large-scale molecule with a molecular weight of approximately 1600.

The large-scale PubChem task highlighted the most significant gap: graph models failed entirely due to scaling issues, while RNNs generated massive, valid molecules that preserved complex features like peptide backbones without explicit instruction.

Flexibility vs. Intuition

The flexibility of string representations allows language models to learn a "grammar" that adapts to novel or massive structures. In contrast, graph models like JTVAE are often limited by fixed vocabularies of chemical substructures. While SELFIES ensures 100% validity, SMILES-based models often provided a closer match to the physical property distributions of the training data.

Conclusion

Simple language models prove to be powerful tools for molecular generation, often surpassing sophisticated graph models in capturing the diversity and scale of chemical space. While they currently lack inherent 3D geometric knowledge, their ability to scale and represent complex distributions makes them a robust foundation for future inverse design tasks. Future research may focus on integrating 3D spatial data into these flexible sequence-based architectures.

Summary updated

BibTeX
@inproceedings{flamshepherd2022language,
  author = {Daniel Flam-Shepherd and Kevin Zhu and Alán Aspuru‐Guzik},
  title = {{Language models can learn complex molecular distributions}},
  booktitle = {Nature Communications},
  year = {2022},
  doi = {10.1038/s41467-022-30839-x},
}
Figure