arXiv:2609.35649cs.LGSep 2026

Manuscript Offprint

arXiv:2609.35649

Transferable Mass Spectrum Prediction via Reference-Guided Test-time Specialization

Yunhua Zhong, Runting Li, Yifan Li, Pan Liu, Zhiwen Yang, Zikun Wang, Yixuan Tang, Jun Xia

ABSTRACT

Tandem mass spectrum prediction supports compound identification across metabolomics, natural-product discovery, and environmental analysis. However, pretrained predictors often degrade under shifts in chemical space and acquisition conditions, while retraining domain-specific models from scratch is costly. We introduce SPARC, a retrieval-guided test-time specialization framework that adapts a pretrained predictor using a spectral reference library without accessing test-query spectra. For each target query, SPARC retrieves chemically related reference spectra to recalibrate fragment intensities within the learned fragmentation space. During Transfer, SPARC combines reference-guided spectral adaptation with reliability-aware consistency, using reconstruction behavior on retrieved spectra to selectively preserve trustworthy predictions during continual specialization. Across MassSpecGym, NPLIB1 and application-specific GNPS libraries, SPARC improves spectral prediction under multiple transfer settings. These results establish retrieval-guided test-time specialization as a practical strategy for extending pretrained MS/MS predictors to specific chemical and acquisition domains, with continual test-time training providing further refinement during deployment.

1 INTRODUCTION

Tandem mass spectrometry is central to molecular annotation, natural-product discovery (Dührkop et al., 2019; Wang et al., 2016) and environmental analysis (Schymanski et al., 2014). By estimating fragment-ion masses and intensities from molecular structures, molecule-to-spectrum predictors extend spectral reference coverage beyond available experimental measurements (Goldman et al., 2024; Murphy et al., 2023; Nowatzky et al., 2025; Young et al., 2024a). Their performance, however, depends on the chemical and acquisition distributions represented during training (Bremer et al., 2022; Young et al., 2024a). Large spectral libraries expose a model to broader chemical space and fragmentation behavior than a single study can provide (Gupta et al., 2026; Murphy et al., 2023). Real-world deployment rarely queries this space uniformly. Each application emphasizes a particular molecular distribution together with its own adducts, ionization modes, instruments, collision energies, and metadata. These factors can change spectral similarity and prediction performance (Bremer et al., 2022; Hoang et al., 2024; Liu et al., 2025). Consequently, broad training coverage does not ensure accurate predictions for the chemical space and acquisition condition of a particular study.

This mismatch produces a practical generalization problem. Changes in acquisition conditions alter the mapping from molecular structure to fragment intensities (Bremer et al., 2022). Study-defined molecular distributions can also concentrate predictions in regions that were sparse during source training (Bushuiev et al., 2024). Adduct-dependent fragmentation provides a concrete example. Compounds retained under one precursor ion may lack paired spectra under another condition. The same molecule can also fragment differently across adducts (Schmid et al., 2021), creating coverage and chemical-composition gaps. When measured spectra are unavailable for the target molecules, chemically related reference spectra provide an alternative source of domain-specific information. Prior work on spectral representation learning and analogue search has shown that MS/MS neighborhoods can recover chemically related molecules (de Jonge et al., 2023; Huber et al., 2021a). This motivates test-time specialization that adapts the predictor to the queried domain.

Figure

Figure 1: Overview of SPARC. Top: A predictor pretrained on a broad source collection is specialized to a target research domain. Bottom: Target molecules retrieve acquisition-compatible and chemically similar support spectra. The fragment generator remains frozen, while support reconstruction errors calibrate bin-wise reliability of an exponential moving average teacher. The student intensity model optimizes similarity-weighted support reconstruction and reliability-weighted teacher–student consistency, with stochastic restoration and rollback constraining adaptation drift.

Test-time training specializes a pretrained model during inference. In classification, TENT uses prediction entropy as a confidence signal, while CoTTA combines teacher averaging with stochastic restoration to limit error accumulation and forgetting (Wang et al., 2020; 2022). Transferring these ideas to MS/MS prediction, however, requires complementing confidence-based adaptation with an external spectral signal indicating how predictions change.

Spectral entropy summarizes the dispersion of normalized peak intensities (Li et al., 2021), but it does not encode whether peaks occur at the correct locations. Entropy can therefore decrease by suppressing weak peaks without improving the predicted fragmentation pattern. Moreover, target molecular structures identify the chemical region being queried but do not specify how the predicted spectrum should change. Chemically related measured reference spectra provide the missing external signal, while teacher predictions regularize the update and preserve reliable source-model structure.

We introduce SPARC (Spectral Prediction via Adaptation with Retrieval-calibrated Consistency), a retrieval-guided test-time training framework that combines support-guided specialization with drift-aware continual adaptation for pretrained MS/MS predictors (Fig. 1). For each target, SPARC retrieves chemically related labeled spectra using acquisition-aware prioritization and uses their measured intensities to supervise adaptation. In addition, SPARC uses reconstruction errors on retrieved support spectra to weight teacher–student consistency, relaxing teacher constraints in bins with larger support errors. An exponential moving average teacher, stochastic restoration and rollback mechanism constrain continual updates together.

We evaluate SPARC on MassSpecGym and NPLIB1 (Bushuiev et al., 2024; Dührkop et al., 2021), covering specialization to an adduct-defined subset and transfer between spectral libraries. We additionally curate five application-specific GNPS collections using a shared processing pipeline to represent focused scientific domains (Wang et al., 2016). These evaluations show robust improvements in the main benchmark transfer settings and higher entropy similarity across all application libraries. Peak-level analyses further characterize how adaptation improves predictions within the preserved candidate space, revealing increases in precision and F1-score at the peak and intensity level.

References (37)