Applying Contrastive Learning to Stellar Spectra
Abstract
With its wide range of spectroscopic capabilities, the Near Infrared Spectrograph (NIRSpec) on the James Webb Space Telescope (JWST) is expected to usher in a new era of crowded-field extragalactic stellar spectroscopy. However, small sample sizes and limited overlap with ground-based surveys, such as APOGEE, pose challenges for NIRSpec data analysis. In this work, we present StarCLIP: a contrastive self-supervised learning framework that embeds observed APOGEE and ab initio NIRSpec spectra into a unified, physically meaningful latent space. Our approach consists of training convolutional neural networks (CNNs) to recover twenty fundamental stellar properties from single-modal spectroscopic data. We then adopt these pre-trained CNNs as encoders, aligning them via contrastive loss. To simulate realistic NIRSpec observations, we construct semi-empirical, stochastic NIRSpec catalogs and embed them into the shared latent space using MockStarCLIP, a modified CLIP-based framework. Both models enable seamless transfer to downstream tasks, including cosine similarity search and stellar property recovery. Notably, a linear regressor applied to StarCLIP embeddings recovers all twenty stellar properties of interest with r2 scores typically exceeding 0.88, including Teff (with uncertainty ≲ 200 K), log g (≲ 0.07 dex) and [Fe/H] (≲ 0.03 dex) for RGB-like stars. Applying the regressor on MockStarCLIP embeddings yields modestly reduced precision — approximately 450 K for Teff, 0.11 dex for log g and 0.06 dex for [Fe/H]. Ultimately, our approach demonstrates that foundation models for NIRSpec and other spectral surveys with similar constraints are well within reach.