Research
Breaking the Modality Barrier: Generative Modeling for Accurate Molecule Retrieval from Mass Spectra
Overview Research area: Machine learning for analytical chemistry — cross-modal retrieval of molecular structures from tandem mass spectra (MS/MS), combining contrastive representation learning with g
- arXiv
- 2511.06259
- Published
- 2025-11-09
- Authors
- Yiwen Zhang, Keyan Ding, Yihang Wu, Xiang Zhuang, Yi Yang, Qiang Zhang, Huajun Chen
AI summary
Overview
- Research area: Machine learning for analytical chemistry — cross-modal retrieval of molecular structures from tandem mass spectra (MS/MS), combining contrastive representation learning with generative language modeling.
- Technical level: Intermediate (accessible two-stage retrieval idea; details of contrastive objectives, cross-attention fusion, and molecular similarity metrics require some familiarity with representation learning and cheminformatics).
- Scope: This paper proposes GLMR, a two-stage framework (pre-retrieval plus generative retrieval) for MS-to-molecule retrieval, and evaluates it on MassSpecGym and a newly constructed MassRET-20k benchmark.
What This Paper Is About
Retrieving the correct molecular structure from a tandem mass spectrum is hard because traditional spectral library matching only works for compounds already in the library, while modern cross-modal deep learning models struggle with modality misalignment — mass spectra describe physical fragmentation while molecular structures describe chemical connectivity, so their learned representations do not line up well. The authors propose GLMR, which first narrows the database down to a handful of candidate molecules using contrastive alignment, then uses a generative language model conditioned on both the spectrum and those candidates to produce a refined molecule that re-ranks them. The goal is more accurate, more generalizable, library-free compound identification.
Key Contributions
- A generative retrieval framework for MS-to-molecule retrieval. GLMR uses a two-stage design — pre-retrieval via cross-modal contrastive alignment, followed by generative retrieval via a context-aware molecule generator — to mitigate cross-modal misalignment by reframing cross-modal retrieval as a more tractable unimodal molecule retrieval.
- A new evaluation benchmark, MassRET-20k. Built from the NIST2020 database with molecules overlapping the MassSpecGym training set removed, yielding approximately 20k spectrum-molecule pairs, 12 ionization adduct types, and normalized collision energy for all entries (versus two adducts and 53% collision-energy coverage in MassSpecGym).
- State-of-the-art retrieval results. GLMR outperforms all baselines on both MassSpecGym and MassRET-20k, with the abstract reporting over 40% improvement in top-1 accuracy.
- Analysis of modality alignment and generation quality. The paper introduces a modality gap metric to show progressive alignment across the two stages, and separately evaluates the generative model's molecular structure quality using MCES, Morgan Tanimoto, and RDK Tanimoto.
Main Findings
- MassSpecGym, weight-based library: GLMR reaches Recall@1 64.172%, Recall@5 72.961%, Recall@20 78.782%, MRR 67.817%, and MCES@1 11.14, compared with the previous state-of-the-art JESTR at Recall@1 17.617%, Recall@5 40.355%, Recall@20 64.764%, MRR 29.121%, and MCES@1 15.82.
- MassSpecGym, formula-based library: GLMR reaches Recall@1 68.478%, Recall@5 78.087%, Recall@20 84.216%, MRR 72.472%, and MCES@1 5.05, versus JESTR at Recall@1 11.772%, Recall@5 33.258%, Recall@20 61.006%, MRR 22.825%, and MCES@1 11.73. The paper states this is a 46% and 56% improvement in Recall@1 over JESTR on the weight-based and formula-based tasks respectively.
- Why the baseline gap exists: The paper reports that JESTR, the current state-of-the-art, shows top-1 accuracy below 20% on MassSpecGym, which the authors attribute to limited cross-modal alignment capability.
- Zero-shot generalization on MassRET-20k: All models are trained only on the MassSpecGym training set and evaluated on MassRET-20k. GLMR remains best, with weight-based Recall@1 54.042%, Recall@5 64.347%, Recall@20 72.984%, MRR 58.835%, MCES@1 12.08; and formula-based Recall@1 51.141%, Recall@5 60.062%, Recall@20 70.671%, MRR 55.565%, MCES@1 6.94 (JESTR weight-based, for comparison: Recall@1 16.490%, MRR 27.454%, MCES@1 18.03).
- Modality gap shrinks in two steps: Using the metric MG(E_i) = 1 − cos(E_i^t, E_i^m), the kernel density estimate on MassSpecGym shifts leftward after pre-retrieval and is reduced further after generative retrieval, indicating progressively better alignment between spectra and molecules.
- Generation quality ranks second: On the MassSpecGym test set, the authors' generative model scores MCES 21.83, Morgan Tanimoto 0.21, and RDK Tanimoto 0.42 — second only to DiffMS (MCES 18.45, Morgan Tanimoto 0.28, RDK Tanimoto 0.49), and ahead of SMILES-Trans (79.39 / 0.07 / 0.03), SELFIES-Trans (33.28 / 0.10 / 0.08), SPEC2MOL (37.76 / 0.12 / 0.19), and MADGEN_Pred (74.19 / 0.08 / 0.13).
- Both stages are necessary (ablation on MassSpecGym): Removing generative retrieval drops weight-based Recall@1 to 20.341% and formula-based Recall@1 to 46.030%; removing pre-retrieval gives 41.501% and 52.968%; the full model reaches 64.172% and 68.478%. The paper notes that generative retrieval used alone outperforms pre-retrieval used alone, but the combination is best.
- K selection: Most metrics plateau when K > 40, so K = 40 pre-retrieved candidates is chosen as the balance between accuracy and computational cost.
Methodology in Plain English
GLMR works in two stages.
Stage one — pre-retrieval. A molecular encoder (ChemFormer, pre-trained on the ZINC database of billions of compounds) reads a molecule as a SMILES string, and a Transformer-based spectral encoder reads a mass spectrum as a sequence of (m/z, intensity) tuples with intensities normalized to (0, 1] — notably avoiding the peak-binning used by earlier methods — then averages over peaks. The two encoders are trained with a CLIP-style dual Info-NCE loss: one direction pulls a molecule toward its own spectrum against spectra perturbed by random intensity changes, the other pulls a spectrum toward its own molecule against other molecules in the batch. Only the spectral encoder is updated; the molecular encoder stays frozen, for 300 epochs at temperature 0.1. At inference, molecules in the library are ranked by cosine similarity to the spectrum embedding, and the top K = 40 become candidate priors.
Stage two — generative retrieval. A cross-fusion module uses cross-attention with the spectral encoding as query and the K candidate molecule encodings as keys and values, producing a fused representation. A ChemFormer decoder then generates a SMILES string for the target molecule conditioned on that fused representation, trained by maximizing the conditional token likelihood for 30 epochs while both encoders remain frozen (only the fusion module and decoder are updated). At inference, beam search with beam size 5 and maximum sequence length 512 produces candidate SMILES; the first generated molecule is encoded and compared by cosine similarity to the pre-retrieved candidates, which are re-ranked to give the final output. Both stages use AdamW with weight decay 0.1 and learning rate 1e-4.
Why This Matters
Research impact. The paper reframes MS-to-molecule retrieval from an alignment problem into a generation-plus-re-ranking problem, and shows that a generative model conditioned on a short candidate list can substantially outperform direct cross-modal embedding matching. It also contributes a harder, more realistic benchmark (MassRET-20k) with 12 ionization adducts and complete collision-energy metadata, built from a non-open-source database (NIST2020) to avoid overlap with MassSpecGym training data — giving the field a stricter zero-shot generalization test.
Real-world applications.
- Metabolomics, where identifying unknown metabolites from MS/MS spectra is a routine bottleneck.
- Natural products discovery, where novel compounds are by definition absent from spectral libraries.
- Drug development, where rapid compound identification shortens structural analysis workflows.
- Library-free compound identification more broadly, replacing expensive and time-consuming structural analysis experiments.
Industry relevance. Spectral library matching is bounded by library coverage; a model that generalizes to unseen spectra and varying ionization conditions without needing a reference spectrum for the target compound is directly relevant to analytical labs, instrument vendors, and pharmaceutical and environmental testing workflows.
Future Directions
- Faster inference. The authors propose designing lightweight fusion and generation modules, since the two-stage pipeline with K = 40 candidates and beam search adds computation.
- Chemically constrained generation. They suggest incorporating explicit chemical constraints or syntactic rules during generation to improve the validity of generated molecular structures.
- Closing the generation gap. The generative model ranks second to DiffMS on the MassSpecGym test set (MCES 21.83 versus 18.45), so improving de-novo generation quality is an open lever on final retrieval accuracy.
- Post-retrieval refinement and re-ranking. The paper's final retrieval output is a re-ranked candidate list rather than a new molecule; how far post-retrieval refinement can be pushed, and how sensitive this is to the choice of molecular similarity function, is not settled by the reported analysis.
Target Audience
Researchers and practitioners in machine learning for the chemical and life sciences — particularly those working on cross-modal retrieval, contrastive representation learning, and generative molecular modeling. Also relevant to analytical chemists and mass spectrometry specialists in metabolomics, natural products, and drug development who need library-free compound identification, and to benchmark builders interested in dataset construction and zero-shot generalization evaluation. Readers need basic familiarity with contrastive learning and cheminformatics representations (SMILES, molecular fingerprints, MCES) to follow the methodology in detail.
Authors’ abstract
Retrieving molecular structures from tandem mass spectra is a crucial step in rapid compound identification. Existing retrieval methods, such as traditional mass spectral library matching, suffer from limited spectral library coverage, while recent cross-modal representation learning frameworks often encounter modality misalignment, resulting in suboptimal retrieval accuracy and generalization. To address these limitations, we propose GLMR, a Generative Language Model-based Retrieval framework that mitigates the cross-modal misalignment through a two-stage process. In the pre-retrieval stage, a contrastive learning-based model identifies top candidate molecules as contextual priors for the input mass spectrum. In the generative retrieval stage, these candidate molecules are integrated with the input mass spectrum to guide a generative model in producing refined molecular structures, which are then used to re-rank the candidates based on molecular similarity. Experiments on both MassSpecGym and the proposed MassRET-20k dataset demonstrate that GLMR significantly outperforms existing methods, achieving over 40% improvement in top-1 accuracy and exhibiting strong generalizability.