GP-MoLFormer-Sim: Test Time Molecular Optimization Through Contextual Similarity Guidance

Jirí Navrátil, Jarret Ross, Payel Das, Youssef Mroueh, Samuel C. Hoffman, Vijil Chenthamarakshan, Brian Belgodere

TL;DR

GP-MoLFormer-Sim is a training-free method that steers pre-trained Chemical Language Models (CLMs) during test-time by adjusting token probabilities based on contextual similarity to target molecules. When integrated into a Genetic Algorithm framework (GP-MoLFormer-Sim+GA), it outperforms existing training-free baselines on standard molecular optimization benchmarks under a strict, realistic black-box setting.

What Problem Does This Paper Address?

Designing novel functional molecules with specific properties is a cornerstone of drug discovery and material science. However, searching through the astronomical space of possible chemical structures is incredibly challenging.

While deep generative models and Genetic Algorithms (GAs) have shown promise, combining them typically requires computationally expensive retraining or fine-tuning to adapt the model to a specific target property. Recently, Large Language Models (LLMs) like GPT-4 have been used within GAs to propose new molecular candidates. However, these LLM approaches often inadvertently "cheat" by receiving the name or structure of the target molecule directly in the prompt—breaking the realistic assumption that the evaluation oracle is a strict black box.

The authors introduce a method to guide molecular generation on the fly without any retraining, while strictly respecting the black-box nature of the optimization problem.

Methods

The core innovation is GP-MoLFormer-Sim, which utilizes a pre-trained, 47-million-parameter SMILES-based chemical language model called GP-MoLFormer.

Instead of altering the model's weights, the authors update its autoregressive decoding policy at every step of generation using a technique called logit tilting:

  1. Contextual Similarity Evaluation: At each decoding step, the method extracts the hidden representations (embeddings) of the sequence generated so far, appended with each potential next token from the vocabulary.
  2. Logit Tilting: It calculates the cosine similarity between these candidate embeddings and the embeddings of the target "guide" molecules. The model's raw output logits are then mathematically mixed with this similarity score. A mixing parameter ($\alpha$) controls how strongly the generation is steered toward the targets versus exploring the base model's natural chemical distribution.
  3. Kernel Density Approximation: To handle multiple target molecules simultaneously, the authors optionally use Random Fourier Features (RFF) to approximate a Gaussian kernel distance, ensuring tight local control around the target space.

The authors further embed this guided generation technique as a mutation operator within a cyclical Genetic Algorithm framework (GP-MoLFormer-Sim+GA), as illustrated below:

Overview of the GP-MOLFORMER-SIM+GA process

Datasets

The method was evaluated using two primary setups:

  • Trypsin Inhibitor Targets: Five specific trypsin inhibitors were used to evaluate simple similarity-guided lead optimization.
  • Practical Molecular Optimization (PMO) Benchmark: A standard benchmark consisting of 23 single-objective optimization tasks spanning property optimization, molecular rediscovery, and structure-based drug design.
  • ZINC & PubChem: The underlying GP-MoLFormer model was pre-trained on ~650 million canonical SMILES strings from these databases, and ZINC was used to initialize the starting populations for the GA.

Key Insights and Ideas

  • Steering via Internal Representations: The paper demonstrates that a CLM's internal contextual representations are rich enough to calculate meaningful molecular similarities on the fly. No external reward models or reinforcement learning loops are required to guide the generation.
  • Exposing the LLM Prompt Leak: A major "aha moment" in the paper involves MOLLEO, a state-of-the-art baseline that uses GPT-4. The authors discovered that MOLLEO's high performance relies heavily on the fact that the target molecule's name is explicitly written in its text prompt (e.g., "thiothixene rediscovery"). Because GPT-4 has memorized these common molecules during pre-training, it isn't truly solving a black-box problem.
  • True Black-Box Superiority: When the authors redacted the target molecule names from the prompts to enforce a fair, strict black-box setting, MOLLEO’s performance dropped by ~33%, allowing GP-MoLFormer-Sim+GA to cleanly outperform it.

Key Results

  • High Sample Efficiency: On the PMO benchmark limited to 10,000 oracle calls, GP-MoLFormer-Sim+GA ranked second overall among all training-free baselines when competing against the unredacted (advantaged) MOLLEO, and ranked first when a true black-box setting was enforced.
  • Controllable Generation: By tuning the mixing strength ($\alpha$) and temperature ($\tau$), the method successfully clusters generated molecules tightly around target spaces or allows for wider exploration, as visualized via t-SNE projections:
Guided generations around five trypsin inhibitor targets under different parameter settings
  • Computational Efficiency: Because it is training-free, the method requires minimal resources. It runs comfortably on a single A100 GPU with a VRAM footprint under 8 GB. Generating a guided token takes just 0.049 seconds—only about four times slower than completely unguided, unconditional generation.

Limitations and Future Work

While powerful, the authors note a few limitations:

  • Model and Domain Specificity: The framework has currently only been validated using the GP-MoLFormer architecture and SMILES strings. Its performance on other architectures or alternative molecular representations (like SELFIES) remains untested.
  • No Negative Guidance: The current formulation only steers towards desirable target molecules. It is still an open question how to efficiently incorporate "negative targets" (molecules or substructures to actively avoid, such as toxic groups).
  • Single-Objective Focus: The framework is optimized for single properties. Extending logit tilting to multi-objective optimization (balancing multiple competing molecular properties simultaneously) is highlighted as a key direction for future research.

Summary updated

BibTeX
@inproceedings{navratil2026gp,
  author = {Jirí Navrátil and Jarret Ross and Payel Das and Youssef Mroueh and Samuel C. Hoffman and Vijil Chenthamarakshan and Brian Belgodere},
  title = {{GP-MoLFormer-Sim: Test Time Molecular Optimization Through Contextual Similarity Guidance}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  doi = {10.1609/aaai.v40i29.39634},
}
Figure