Test-Time Tuned Language Models Enable End-to-end De Novo Molecular Structure Generation from MS/MS Spectra

Laura Mismetti, Marvin Alberts, Andreas Krause, Mara Graziani

TL;DR

This paper introduces a novel end-to-end transformer model for generating molecular structures directly from MS/MS spectra and chemical formulas. By employing a "test-time tuning" strategy, the model dynamically adapts to new experimental data, significantly improving accuracy, especially for out-of-distribution spectra, and providing chemically meaningful candidates even when exact matches aren't found.

What Problem Does This Paper Address?

Identifying unknown small molecules is crucial in fields like metabolomics and drug discovery, with tandem mass spectrometry (MS/MS) being a key technique. However, elucidating molecular structures from MS/MS spectra is challenging due to the complex fragmentation process and the vast chemical space. Existing methods often rely on database matching or multi-step pipelines requiring manual annotations, which struggle with novel molecules and shifts in experimental conditions (domain shift). This paper tackles the problem of robust and accurate de novo molecular structure generation from MS/MS spectra, particularly in scenarios where the test data differs from the training data.

Methods

The core of the proposed solution is an end-to-end transformer encoder-decoder model. This model takes an MS/MS spectrum and its corresponding chemical formula as input and directly predicts the molecular structure in SMILES format.

Key novelties include:

  • End-to-End Generation: Eliminates the need for intermediate steps like fragment annotation or fingerprint prediction, simplifying the pipeline.
  • Test-Time Tuning (TTT): A crucial adaptation strategy. Instead of just fine-tuning on the entire training set, TTT dynamically selects the most informative training samples for adaptation at inference time. This is particularly effective for out-of-distribution data, preventing catastrophic forgetting and improving robustness. The selection is guided by predicted molecular fingerprints.
  • Fingerprint Alignment: An auxiliary loss term during training encourages the model to learn representations that capture chemical information, leading to more plausible SMILES predictions.
  • Formula-Constrained Generation: Ensures that the generated SMILES strings are chemically valid according to the provided molecular formula.

Datasets

The study utilizes several datasets:

  • Simulated MS/MS Spectra: Used for pre-training the model. This dataset is large (3,971,930 spectra) and generated using various simulation techniques (CFM-ID, ICEBERG, SCARF).
  • NPLIB1: An experimental dataset used for tuning and evaluation. The paper uses both the original version (NPLIB1-Full) and a filtered version (NPLIB1-DiffMS) to ensure fair comparison with prior work.
  • MassSpecGym: Another experimental dataset known for its challenging domain shift between training and test sets. Similar to NPLIB1, both the original (MassSpecGym) and a filtered version (MassSpecGym-DiffMS) are used.

Key Insights and Ideas

  • Test-Time Tuning is Crucial for Domain Shift: The paper strongly demonstrates that TTT is essential for handling out-of-distribution spectra, where standard fine-tuning can actually degrade performance. TTT's ability to selectively adapt to relevant data points is key.
  • Simulated Data is a Powerful Pre-training Tool: Pre-training on large-scale simulated spectra significantly boosts zero-shot performance and provides a strong foundation for subsequent adaptation, even though simulated spectra differ from experimental ones.
  • Chemically Meaningful Predictions Matter: Even when the model doesn't predict the exact correct structure, the generated candidates are highly similar to the ground truth (high Tanimoto similarity) and structurally plausible, offering valuable guidance for chemists.
  • End-to-End Simplicity Wins: Removing intermediate steps simplifies the process and appears to improve overall performance and interpretability.

Key Results

  • State-of-the-Art Performance: The proposed TTT approach achieves state-of-the-art Top-1 accuracy on NPLIB1 (12.88%) and MassSpecGym (3.16%), significantly outperforming baselines by up to 67%.
  • Improved Structural Similarity: The generated candidates show significantly higher Tanimoto similarity to the ground truth compared to existing methods (e.g., 83% relative improvement on NPLIB1).
  • Robustness Across Regimes: The TTT framework performs well in both in-distribution (comparable to fine-tuning) and out-of-distribution scenarios (outperforming fine-tuning).
  • Impact of Simulated Data: Pre-training on simulated data leads to substantial improvements in zero-shot performance on NPLIB1-Full (3.84% vs. 0.62%) and MassSpecGym (1.89% vs. 0%).

Limitations and Future Work

  • Scalability of Candidate Pool: Identifying the most informative spectra for TTT becomes computationally demanding as the candidate pool grows. The authors suggest approximate nearest-neighbor or vector-search methods as potential solutions, but integrating them without degrading adaptation quality is a challenge.
  • Dependence on Informative Neighbors: TTT's effectiveness relies on having structurally relevant spectra within the candidate pool. If no such neighbors exist, adaptation is constrained.
  • Spectrum Quality: Noisy or low-quality spectra can hinder the selection process and model updates.
  • Future Work: The authors suggest exploring more efficient candidate pool selection methods and further integrating experimental data to enhance model robustness and accuracy. They also highlight the potential of this approach for various analytical workflows.

Summary updated

BibTeX
@inproceedings{mismetti2026test,
  author = {Laura Mismetti and Marvin Alberts and Andreas Krause and Mara Graziani},
  title = {{Test-Time Tuned Language Models Enable End-to-end De Novo Molecular Structure Generation from MS/MS Spectra}},
  booktitle = {FM4Science @ ICLR},
  year = {2026},
  url = {https://openreview.net/forum?id=iUNLJK9oSj},
}
Figure