SmileyLlama: Modifying Large Language Models for Directed Chemical Space Exploration

Joseph M. Cavanagh, Kunyang Sun, Andrew Gritsevskiy, Dorian Bagni, Yingze Wang, Thomas D. Bannister, Teresa Head-Gordon

TL;DR

The authors introduce SmileyLlama, a method that transforms a general-purpose, open-weight Large Language Model (Meta-Llama-3.1-8B-Instruct) into a powerful Chemical Language Model (CLM) via supervised fine-tuning and direct preference optimization. Instead of acting merely as a conversational assistant, SmileyLlama directly generates valid, novel, and drug-like SMILES strings tailored to user-specified chemical properties. When integrated into a reinforcement learning framework for 3D molecular docking, it demonstrates exceptional data efficiency and diversity, opening up new avenues for directed chemical space exploration.

What Problem Does This Paper Address?

De novo drug discovery relies heavily on Chemical Language Models (CLMs) to navigate the astronomical complexity of chemical space. Traditionally, these models (like LSTMs or GPTs) are trained completely from scratch on massive chemical datasets (e.g., ChEMBL or ZINC). While effective at generating valid molecular strings (SMILES), they lack natural language understanding and require expensive, specialized retraining whenever researchers want to introduce new conditional constraints or multi-objective properties.

Conversely, frontier Large Language Models (LLMs) possess immense natural language capabilities but struggle to natively generate syntactically correct chemical strings or adhere strictly to precise molecular constraints. The authors bridge this gap by proving that a commodity, general-purpose LLM can be adapted into a top-tier generative CLM without losing its underlying linguistic capabilities.

Methods

The researchers developed a two-stage alignment pipeline to create SmileyLlama:

  1. Supervised Fine-Tuning (SFT): They fine-tuned Meta-Llama-3.1-8B-Instruct using Low-Rank Adaptation (LoRA). The training data consisted of pairs where the prompt contained a randomized subset of calculated molecular properties (e.g., molecular weight, hydrogen bond counts, topological polar surface area) and the target output was the corresponding SMILES string.
  2. Direct Preference Optimization (DPO): To ensure the model strictly obeys the user's property constraints, they applied DPO. By pairing successful generations (molecules that matched the prompt criteria) as "winners" and failures as "losers," they updated the model weights to reinforce task-oriented robustness.

For targeted drug discovery, they integrated SmileyLlama into the iMiner reinforcement learning framework, replacing its traditional recurrent neural network component and substituting Proximal Policy Optimization (PPO) with DPO to optimize molecules for 3D protein-ligand binding affinity.

Datasets

  • ChEMBL (v33): A dataset of approximately 2 million drug-like molecules used for the primary SFT and DPO training phases.
  • GuacaMol: A standard benchmark suite used to evaluate the validity, uniqueness, novelty, and distributional frequency of the generated molecules.
  • Enamine Fragment Library: A collection of 320 substructures used to test conditional fragment growth and "scaffold hopping."

Key Insights and Ideas

  • Pre-training from Scratch is Unnecessary: A general-purpose LLM already possesses enough latent structural awareness to be successfully steered into a high-performing CLM with relatively lightweight SFT (~32 hours on a single 4xA40 node).
  • Zero-Shot vs. Few-Shot Paradox: Interestingly, providing the base LLM with 20 in-context examples (twenty-shot) actually decreased the validity of generated SMILES compared to zero-shot generation. The examples biased the model away from its memorized syntax without providing enough structural context to generalize properly.
  • Zero-Shot Multi-Objective Composition: SmileyLlama can successfully combine multiple property constraints in a single prompt during inference (e.g., asking for a specific substructure and low molecular weight), even if it wasn't explicitly trained on that exact combination of constraints.

Key Results

  • Benchmark Performance: On the GuacaMol benchmark, SmileyLlama achieved a validity score of 0.958 and a uniqueness score of 1.000, matching or outperforming traditional CLMs trained from scratch like AAEs and GPTs.
  • Property Distribution: The physical and chemical properties of molecules generated by SmileyLlama closely mirror the distribution of the ChEMBL training set, as visualized in the UMAP and property density plots below.
UMAP and property distribution comparisons between ChEMBL and SmileyLlama
  • DPO Constraint Enforcement: Applying DPO drastically improved prompt adherence. For instance, the success rate for generating molecules satisfying the Lipinski Rule-of-Five jumped from 81.7% (SFT alone) to 97.7% (SFT + DPO).
Fragment growth and property distributions before/after DPO alignment
  • Data Efficiency in RL: When optimized for binding to the SARS-CoV-2 main protease ($M^{pro}$), the SmileyLlama-augmented iMiner framework required only 25% of the training epochs compared to the original iMiner algorithm to achieve similar or superior docking scores, all while maintaining significantly higher molecular diversity.

Limitations and Future Work

Despite its strong performance, SmileyLlama faces a few distinct challenges:

  • Numerical Precision: Like most LLMs, SmileyLlama struggles with exact numerical specifications and performs better when properties are framed as ranges or inequalities (e.g., "$\le 500$ MW").
  • Data-Poor Regimes: The model still underperforms on tasks involving rare chemical structures, such as generating macrocycles or specific warhead-related SMARTS patterns that are infrequently represented in the training data.
  • Diversity vs. Optimization Trade-off: While DPO forces strict adherence to user prompts, it inherently narrows the property distribution, which might limit broad chemical exploration during the early stages of drug discovery.

The authors suggest that scaling this framework to larger foundational LLMs could help preserve more of the model's baseline natural language capabilities while mitigating these limitations.

Summary updated

BibTeX
@inproceedings{cavanagh2024smileyllama,
  author = {Joseph M. Cavanagh and Kunyang Sun and Andrew Gritsevskiy and Dorian Bagni and Yingze Wang and Thomas D. Bannister and Teresa Head-Gordon},
  title = {{SmileyLlama: Modifying Large Language Models for Directed Chemical Space Exploration}},
  booktitle = {AIDrugX @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=LfBIZzQsvg},
}
Figure