Spectral Transformer Neural Processes

Xianhe Chen, Hao Chen, Yingzhen LiNeurIPS 2026

TL;DR

Standard Neural Processes struggle—and often flatline into useless average predictions—when faced with repeating patterns like ocean tides, daily traffic, or striped textures. Spectral Transformer Neural Processes (STNPs) fix this by listening to the "frequencies" of a dataset on the fly, translating distant but rhythmically aligned data points into close neighbors for attention mechanisms. It brings the mathematical elegance of spectral Gaussian Processes into the fast, flexible world of Transformers.

What Problem Does This Paper Address?

Imagine looking at a few scattered measurements of ocean tides over a week and trying to guess the water level next Tuesday, while also knowing how confident you should be. Neural Processes (NPs) are designed for exactly this kind of meta-learning: given a small "context" set of input-output pairs, they predict the underlying function at new "target" locations, complete with uncertainty estimates.

Recently, Transformer Neural Processes (TNPs) cast this as a sequence modeling problem, using attention to let target queries look up relevant context points. While great for smooth, local patterns, TNPs hit a wall when data is periodic (strictly repeating) or quasi-periodic (repeating with drifting amplitude, phase, or shape).

Why? Because standard TNPs embed inputs using ReLU-based MLPs—continuous, piecewise-linear maps that care about Euclidean distance in time or space. To a standard TNP, 9:00 AM today and 9:00 AM next Tuesday are miles apart, even though they sit at the exact same phase of a daily cycle. Prior fixes added translation equivariance (helping models handle shifted inputs) or fixed sinusoidal activations, which fail when every new task has its own unique, unknown rhythm.

Methods

Instead of redesigning the Transformer backbone, the authors reshape the geometry of the input embeddings by introducing a Spectral Aggregator ahead of a standard TNP. Think of it as an on-the-fly prism that breaks context data into its constituent frequencies before the Transformer ever sees it.

Figure 1: Overview of STNPs. (a) An empirical spectrum is estimated from the context set on a fixed frequency grid via cosine/sine projections of centred responses. (b) A CNN responsibility network softly assigns each grid frequency to one of Q mixture components. (c) The discrete spectrum is compressed into a Gaussian mixture with weights, means, and variances induced by the responsibilities. (d) Task-adaptive frequencies sampled from this mixture form spectral embeddings, which are concatenated with the MLP token representation and passed to the TNP predictor.

The novel Spectral Aggregator works in four intuitive steps:

  1. Empirical Spectrum Estimation: It centers the context outputs and projects them onto a fixed grid of cosines and sines to estimate raw spectral energy across frequencies.
  2. Latent Spectral Decomposition: Raw discrete spectra are spiky and tied to grid resolution. A lightweight 1D Convolutional Neural Network (CNN) slides along the frequency axis, looking at local peak shapes and bandwidths to softly assign each grid frequency to one of $Q$ latent components.
  3. Probabilistic Compression: Using those soft assignments, the spiky discrete spectrum is compressed into a clean, continuous Gaussian Mixture (defined by component weights, mean frequencies, and variances).
  4. Sampling & Concatenation: Using the reparameterization trick, the model samples task-adaptive frequencies from this Gaussian mixture to build sinusoidal spectral features.

Finally, these spectral features are concatenated with standard MLP time-domain embeddings and fed into a standard masked TNP encoder.

Datasets

No brand-new datasets are introduced, allowing direct comparisons across established benchmarks:

  • Synthetic 1D Regression: Functions sampled from Gaussian Processes (RBF, Matérn, and Periodic kernels) plus a sharp Sawtooth wave family, tested in-distribution and out-of-distribution (OOD).
  • 2D Image Completion: The Describable Textures Dataset (DTD), framed as spatial regression from 2D pixel coordinates to RGB intensities on $64 \times 64$ crops (sampling 5 to 1,024 context pixels).
  • Real-World Time Series:
  • Six-dataset long-horizon forecasting benchmark: Electricity, ETTh1, Exchange Rate, National Illness, Traffic, and Weather.
  • Imputation: California Traffic Flow (2020 COVID-19 period with irregular volatility).
  • Multivariate short-horizon forecasting: Chichester Harbour (Chimet) UK weather/tide observations (5 attributes across 17 Junes).

Key Insights and Ideas

  • Amortizing Bochner’s Theorem: By Bochner’s theorem, stationary kernels correspond to non-negative spectral measures. In expectation, the dot product of STNP’s sampled spectral features mathematically induces a Spectral Mixture (SM) kernel. When the Transformer computes query-key dot products in attention, it is implicitly performing kernel regression with a task-specific SM kernel inferred in a single forward pass!
  • It’s a Geometry Problem, Not a Capacity Problem: You can't brute-force periodicity by scaling up a vanilla TNP. Scaling TNP from 0.25M to 2.0M parameters left periodic regression log-likelihood completely flat at -0.348. STNP scored 1.12 with just 0.233M parameters.
  • Why the CNN & Mixture Compression Matter: Feeding raw discrete spectra or fixed Fourier features into a TNP underperforms significantly. Using a 1D CNN along the frequency axis captures local spectral geometry (like bandwidth, which governs how fast a quasi-periodic pattern decays), smoothing out grid artifacts.

Key Results

STNP consistently outperforms neural process baselines (including ConvCNP, SConvCNP, and translation-equivariant TETNP) across modalities:

  • Synthetic Regression: On Periodic GP tasks, STNP achieves a target log-likelihood of 1.12, compared to -0.35 for TNP, 0.20 for TETNP, and 0.44 for SConvCNP. Unlike baselines that revert to flat mean predictions in sparse or OOD regions, STNP extrapolates clean waves.
Figure 2: Example predictions on synthetic sawtooth (top) and periodic (bottom) tasks. Columns compare SConvCNP, TETNP, and STNP (ours). Black and red dots denote context and query points respectively. The ground truth is shown in purple, and the blue curve denotes the predictive mean; the bands represent ±2 standard deviations. The shaded regions indicate out-of-distribution ranges.
  • Real-World Time Series: Across the six forecasting benchmarks, STNP cuts TNP's Mean Squared Error (MSE) by 51.3% to 97.1% (e.g., dropping Electricity MSE from 1.012 to 0.179, beating specialized forecasters like Autoformer at 0.201).
Figure 4: Representative forecasting windows on the Electricity and Traffic datasets. The red curve denotes the ground truth and the coloured curve denotes the predictive mean.
  • Texture Completion: On DTD images, STNP achieves the highest PSNR (24.0) and SSIM (0.64), reconstructing crisp global lattices and stripes where TNP blurs and TETNP runs out of GPU memory (even on 8 A100s).
  • Modest Overhead: Because the Spectral Aggregator scales linearly $\mathcal{O}(N)$, quadratic attention still dominates for large $N$. On 4,096-pixel images, STNP adds just 7.2% training time and 11.4% inference time over vanilla TNP.

Limitations and Future Work

  • Independent Output Assumptions: STNP uses a diagonal Gaussian output head (TNP-Diagonal), meaning it predicts uncertainties independently for each target point and variable channel. While the shared spectral embedding captures recurring structure, the likelihood itself cannot model correlated noise across targets or non-Gaussian, multimodal uncertainties.
  • Future Directions: The authors suggest pairing their task-adaptive spectral representations with correlated Gaussian Processes, latent-variable NP heads, or more expressive likelihoods so models can capture joint, multimodal uncertainties across space, time, and channels simultaneously.

Summary updated

Abstract

Time series, spatial data, and images are natural applications of Neural Processes. However, when such data exhibit strong periodicity and quasi-periodicity, existing methods often suffer from underfitting and generalise poorly beyond the training distribution. In this work, we propose Spectral Transformer Neural Processes (STNPs), a frequency-aware extension of Transformer Neural Processes (TNPs). STNPs introduce a Spectral Aggregator that estimates an empirical context spectrum, compresses it into a spectral mixture, samples task-adaptive spectral features, and concatenates them with time-domain embeddings, thereby injecting a spectral-mixture-kernel bias into TNPs. This design reshapes the similarity geometry, allowing inputs that are distant in Euclidean space to remain close in an induced periodic manifold while enhancing time--frequency interactions. Extensive experiments on synthetic regression tasks, real-world time-series datasets, and an image dataset demonstrate that STNPs consistently improve predictive performance over existing baselines, extending Neural Processes beyond translation equivariance toward effective modelling of periodicity and quasi-periodicity.
BibTeX
@inproceedings{chen2026spectral,
  author = {XIANHE CHEN and Hao Chen and Yingzhen Li},
  title = {{Spectral Transformer Neural Processes}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=GNyLIJGdwZ},
}
Figure