arXiv:2610.30746cs.LGOct 2026

Manuscript Offprint

arXiv:2610.30746

Wavenumber-Aware Deep Learning for Robust Analysis of Raman Spectra

Jihwan Kim, Jaeseong Heo, Yujin Kim, Sang Bin Yoon, Chanjoong Kim, Kwang-Im Oh, Hyon Bin Na, Kyungwon Kwak, Myeongkee Park, Joonyoung F. Joung

Abstract

Machine-learning models for spectroscopy usually treat a spectrum as a fixed-grid intensity vector, leaving the physical coordinate implicit in the array index. Such models are tied to a single sampling grid, spectral range and resolution, which limits their use when measurement conditions change. Here we represent each spectral point as a pair of intensity and wavenumber and compute Transformer positional encodings from the wavenumber itself. On Raman spectra of three bacterial species and their synthetic mixtures, this representation remained robust to noise, sparser sampling and partial spectral coverage across convolutional, residual and Transformer networks. In controlled comparisons, wavenumber-based encoding outperformed index-based and learned encodings under partial observation and retained its performance on sampling grids never seen during training, where index-based encoding degraded. These findings were reproduced on a public 30-isolate bacterial benchmark. Explicit physical coordinates offer a simple route to robust spectral analysis under variable measurement conditions.

Keywords: Raman spectroscopy, deep learning, wavenumber-aware representation, bacterial identification, robust spectral analysis

1 Introduction

Machine learning has become a standard tool for the analysis of spectroscopic measurements across modalities, including infrared and vibrational spectroscopy, [1−3]^{[1-3]} nuclear magnetic resonance, [4−6]^{[4-6]} mass spectrometry, [7,8]^{[7,8]} optical absorption and emission spectroscopy, [9−11]^{[9-11]} and X-ray diffraction, [12,13]^{[12,13]} and the field has recently been surveyed. [14]^{[14]} Despite the diversity of these techniques, they share a common structure: each measurement is defined over an explicit physical coordinate, such as wavenumber, chemical shift, mass-to-charge ratio, wavelength, or diffraction angle, and the recorded spectrum is a set of intensity values at positions along this coordinate axis.

In nearly all of these applications, however, spectra are supplied to learning models as fixed-grid intensity vectors, in which the physical coordinate is encoded only implicitly through the array index. [2,4,15−24]^{[2,4,15-24]} The consequences of this convention have long been recognized in chemometrics as the calibration-transfer problem: models built on one instrument degrade on another because sampling positions, resolution, and spectral range differ, and decades of standardization methods have been developed to compensate for these differences. [25,26]^{[25,26]} Deep-learning approaches inherit the same limitation, and recent work has addressed it through domain adaptation between instruments. [27]^{[27]} The representation itself, in which measured intensities are detached from their physical coordinates, has received comparatively little attention.

This convention was established with convolutional neural networks (CNNs), the first deep architectures to be widely adopted for spectra, and it is shared across modalities. In powder X-ray diffraction, Park et al. classified crystal symmetry from 10,001 intensity values recorded over a fixed range of diffraction angles, and described the diffraction pattern as being treated like a picture rather than as a set of peak positions and intensities. [12]^{[12]} Lee et al. identified the constituent phases of multiphase mixtures from synthetic patterns of 4,501 intensity values in the same manner. [13]^{[13]} In nuclear magnetic resonance, Hu et al. interpolated each 1{}^{1}H spectrum onto a grid of 28,000 points between -2 and 12 ppm before passing it to a CNN, and binned the 13{}^{13}C chemical shifts into 80 fixed intervals. [5]^{[5]} CNNs for near-infrared, infrared, and Raman spectra follow the same design. [15,17−19,21]^{[15,17-19,21]} For Raman-based bacterial identification, Ho et al. established a large and widely used public benchmark of approximately 60,000 spectra across 30 reference isolates and classified them with a deep residual

CNN. [20]^{[20]} Notably, their architecture avoided pooling layers and instead used strided convolutions to preserve the exact positions of spectral peaks, an architectural choice reflecting that positional information along the spectral axis is essential for spectral discrimination. However, the network in all of these models receives only the intensities. The physical coordinate does not appear in the input, and position along the axis is conveyed solely by the array index.

Transformer architectures have more recently been adopted because self-attention can relate distant spectral features regardless of their distance along the axis, which convolutional filters with local receptive fields capture less efficiently. [28]^{[28]} However, the input convention has been remained unchanged. For structure elucidation from infrared spectra, Alberts et al. interpolated each spectrum to 400 points and supplied the integer-valued intensities as a token sequence, so that the position of a token in the sequence stands for its wavenumber. [29]^{[29]} Their simulated pretraining spectra began at 400 cm −1^{-1}, whereas their experimental spectra began at 450 or 550 cm −1^{-1}. The missing low-wavenumber region was therefore filled with zeros. In addition, a separate model was pretrained for each starting wavenumber. Wu et al. increased the sampling to 3,200 uniformly spaced points and grouped them into fixed-length patches within a self-attention embedding layer, padding unmeasured regions with zeros. [30]^{[30]} In hyperspectral imaging, SpectralFormer embeds groups of neighboring spectral channels and assigns positions by channel order. [31]^{[31]} It was trained separately on data from three sensors that record 200, 103, and 144 spectral channels. Transformer models for Raman spectra follow the same pattern: RamanFormer performs mixture-component quantification using fixed-length spectral patches, [22]^{[22]} the fragment-fusion Transformer classifies single-cell spectra using biologically motivated spectral fragments, [23]^{[23]} and related Transformer designs have been explored for other Raman classification tasks. [32]^{[32]} However, unlike natural language, spectra are continuous physical measurements rather than sequences of discrete symbols. Each measured intensity is inherently associated with a physical coordinate, and together they define the spectral observation. Because standard Transformers require tokenized inputs, existing spectral Transformers introduce an explicit discretization step, dividing spectra into resampled points, patches, fragments, or band groups that are subsequently treated as tokens whose positions are given by the token index.

Mass spectrometry is the exception. A tandem mass spectrum is processed as a list of peaks, each a pair of mass-to-charge ratio (m/z)(m/z) and intensity, which is a sparse set rather than a sampled curve. Transformer models for mass spectra encode the coordinate directly: Casanovo encodes the m/zm/z value of each peak with a set of fixed sinusoidal functions and its intensity with a learned linear layer, and uses the peaks without discretizing the m/zm/z axis, [7]^{[7]} and DreaMS expands each m/zm/z value into Fourier features. [8]^{[8]} Both models retain only the most intense peaks of a spectrum (up to 150 in Casanovo and 60 to 100 in DreaMS). Bushuiev et al. further reported that replacing the continuous m/zm/z encoding with binned m/zm/z tokens decreases performance. [8]^{[8]} Optical, magnetic resonance, and diffraction spectra differ from such peak lists. They are densely sampled continuous signals in which band shapes, shoulders, overlapping bands, and the baseline between bands are all part of the measurement, and every sampled point is an observation. Even a region without any band is informative, because the absence of a band at a given coordinate is itself a measured result. For these signals the array index has served as a substitute for the coordinate, and coordinate-based encoding of the individual sampled points has, to our knowledge, not been examined.

Although the fixed-grid convention enables the use of standard architectures, it introduces several conceptual and practical limitations. First, the learned representation depends on design choices such as the resampling grid, patch lengths, fragment boundaries, and embedding strategies; [33]^{[33]} even when these choices are well motivated, for example fragment boundaries aligned with biochemically meaningful spectral regions, [23]^{[23]} they remain anchored to fixed positions on a predetermined spectral grid. Second, a fixed grid ties the model to a particular spectral resolution, sampling density, and spectral range, [22,23,29,30]^{[22,23,29,30]} so that spectra acquired under other settings must be interpolated, padded, or handled by a separately trained model. Third, spectral regions that are unavailable due to instrumental limitations, fluorescence interference, detector saturation, or preprocessing procedures are not directly compatible with a fixed-grid representation. As a result, existing approaches implicitly assume that spectra are complete and uniformly sampled. Real-world measurements often violate these assumptions.

When all spectra are acquired on the same instrument over the same spectral range, these limitations are of little practical consequence: array indices are then in one-to-one correspondence with physical coordinates, and a model can learn this correspondence implicitly without loss of information. These limitations become important when spectra are acquired using different instruments or under varying experimental conditions.

In this work, we examine this representational question in the context of Raman spectroscopy and bacterial identification, a setting in which its consequences are particularly acute. Raman spectroscopy provides label-free vibrational fingerprints of molecular composition and has emerged as a promising route to rapid, reagent-free bacterial identification. [34,35]^{[34,35]} The task is demanding: bacterial cells share most of their biochemical components, so their spectra overlap strongly and the discriminative information is distributed across many vibrational bands rather than concentrated in isolated peaks. [20,36]^{[20,36]} Therefore, effective classification requires models capable of capturing long-range relationships among spectral features while remaining robust to measurement variability, [22,23,27]^{[22,23,27]} which makes bacterial identification a challenging task for the representational question raised above. In practice, Raman spectra may differ in spectral resolution, sampling density, spectral range, and signal quality, often requiring interpolation, resampling, or model fine-tuning to compensate for instrument-specific differences. [27]^{[27]} As illustrated in Fig. 1a, the same Raman signal may be acquired with different sampling densities, spectral ranges, or incomplete spectral coverage. Therefore, conventional fixed-grid representations require interpolation, resampling, or padding before inference, potentially introducing artifacts and reducing robustness across acquisition conditions.

a Raman spectra under varying measurement conditions

b Conventional fixed-grid representation

c Proposed wavenumber-aware representation

Figure

Fig. 1 Overview of spectral variability and representation strategies for Raman data. (a) Raman spectra acquired under varying measurement conditions, including differences in sampling density or resolution and partial observation due to missing or unreliable regions. (b) Conventional fixed-grid representations encode spectra as one-dimensional signals with implicitly defined wavenumber coordinates, requiring a fixed discretization and full spectral coverage. Such representations are not well suited for spectra with varying sampling densities or incomplete observations. (c) Proposed wavenumber-aware representation, where spectral intensity (I) and corresponding wavenumber ( ω\omega) are explicitly incorporated as separate input channels. This formulation enables flexible handling of varying sampling densities and partial spectral inputs without relying on a fixed discretization.

We hypothesized that, under such varying acquisition conditions, the primary limitation lies not in the learning architecture itself but in the conventional fixed-grid representation of Raman spectra, where physical wavenumber information is implicitly encoded through sampling indices rather than explicitly represented. A Raman spectrum is fundamentally a mapping between signal intensity and its corresponding physical coordinate (wavenumber), yet most existing approaches represent it solely as an intensity vector on a fixed sampling grid (Fig. 1b). Here, we explicitly incorporate wavenumber coordinates alongside intensity values, treating each spectral point as a physically defined observation rather than merely an index in a discretized sequence (Fig. 1c). In Transformer architectures, this corresponds to computing positional encodings directly from physical wavenumber coordinates rather than from sequence indices, enabling a controlled comparison against standard index-based and learned positional encodings under identical training conditions. This representation naturally accommodates variations in spectral resolution, sampling density, and spectral coverage without requiring resampling onto a common grid at inference time.

In this study, we propose a wavenumber-aware deep learning approach for bacterial identification from Raman spectra. Using experimentally acquired spectra from multiple bacterial species, we evaluate the proposed representation under realistic measurement scenarios, including spectral mixing, additive noise, reduced sampling density, and partial spectral observation. We further benchmark wavenumber-aware inputs against constant, index-based, and learned positional encodings under identical data and augmentation conditions, and examine generalization to sampling grids whose wavenumber positions never appear during training. The central comparison is carried out in parallel on our in-house dataset and on the independent 30-isolate public benchmark of Ho et al. [20]^{[20]} Our results demonstrate that explicitly incorporating physical wavenumber information provides a physically meaningful representation that improves robustness across diverse acquisition conditions. These properties are particularly relevant to practical Raman sensing scenarios, such as portable or field-deployed systems, in which spectra must be analyzed under variable and often degraded measurement conditions.