Calibrating Scientific Foundation Models with Inference-Time Stochastic Attention

Akash Yadav, Taiwo Adebiyi, Ruda ZhangNeurIPS 2026

TL;DR

Large transformer models are revolutionizing scientific fields like weather forecasting, yet they typically spit out a single, overconfident answer without telling us how sure they are. This paper introduces Stochastic Attention, a clever inference-time trick that unlocks reliable, calibrated uncertainty bars from frozen, pretrained transformers—no expensive retraining required. By turning deterministic attention weights into a controllable sampling game, it matches or beats heavy-duty ensemble methods in minutes rather than days.

What Problem Does This Paper Address?

Imagine a weather model predicting a calm 72°F tomorrow. Should you pack an umbrella just in case? Without calibrated uncertainty, a single point forecast leaves high-stakes decision-makers flying blind.

Evaluating uncertainty isn't one-dimensional; it balances four distinct axes: accuracy (getting the trend right), calibration (if the model claims 90% confidence, is it right 90% of the time?), sharpness (keeping error bars tight enough to actually be useful), and computational cost.

Figure 1: Useful uncertainty in scientific foundation models is multi-dimensional. (a) ClimaX 72-hour weather forecasting: ERA5 ground truth, model forecast, and bias. (b) Accuracy, calibration, sharpness, and cost as complementary axes of uncertainty quality. (c) Sinusoidal example: predictors recovering the same trend can attach qualitatively different uncertainty intervals to it.

Traditional ways to get uncertainty—like training ten separate models from scratch (Deep Ensembles) or modifying architectures during training—become prohibitively expensive as scientific foundation models scale into hundreds of millions or billions of parameters. We need a way to extract trustworthy, sharp uncertainty directly from frozen, already-trained transformers at minimal cost.

Methods

The authors observe a neat mathematical truth hiding in plain sight: standard transformer attention is already probabilistic. Softmax weights form a probability distribution over tokens, and the standard attention output is just the exact expected value under that distribution.

Instead of computing that exact average, Stochastic Attention (SA) replaces it at inference time with a finite-sample approximation:

  1. Multinomial Sampling: Given the standard attention probabilities for a query, SA draws $\nu$ random token selections (with replacement) and averages their value vectors.
  2. The Concentration Knob ($\nu$): This single integer parameter $\nu$ acts like a sample size. Small $\nu$ injects more randomness; as $\nu \to \infty$, SA smoothly converges right back to the original deterministic transformer. Crucially, each attention layer preserves the pretrained model's exact behavior on average.
  3. Fast Post-Hoc Calibration: Running multiple forward passes gives an ensemble of predictions. To set $\nu$ without guesswork, the authors define a 1D calibration objective on a small held-out dataset: pick the $\nu$ where the spread of SA's stochastic predictions matches the magnitude of the deterministic model's actual errors. Using Bayesian optimization, tuning this single parameter takes mere minutes.

Datasets

No new benchmarks are introduced; instead, the authors test SA across three diverse existing domains:

  • Time-Series Forecasting: ETT-small benchmarks (ETTh1, ETTh2, ETTm1, ETTm2) using a fine-tuned TimesFM model in a low-data regime.
  • Global Weather Forecasting: Gridded ERA5 atmospheric data (predicting 72-hour geopotential $Z_{500}$) using the 108M-parameter ClimaX foundation model.
  • Tabular Regression: Eight standard UCI scientific and engineering datasets (including Concrete, Energy, Naval, Yacht, and Protein) using an FT-Transformer trained from scratch.

Key Insights and Ideas

  • Free Input-Dependent Uncertainty ("Shape vs. Scale"): Post-hoc temperature scaling just multiplies every error bar by the same global constant. SA doesn't have to design input-dependent spread—it inherits it naturally from the transformer! When attention concentrates on one token (or tokens with similar values), variance is tiny. When attention splits across tokens with wildly different values, variance blooms automatically. The parameter $\nu$ only tunes the global scale.
  • Don't Break the Pretrained Brain: Baseline attention-noise methods that modify attention during fine-tuning (like Hierarchical Stochastic Attention) actively disrupt pretrained weights, causing ClimaX's forecast accuracy to tank by 19%. Because SA is mean-preserving and applied strictly at inference, the pretrained model stays intact.
  • One Curve, Multiple Operating Points: Depending on whether a practitioner cares most about strict statistical calibration or optimizing proper scoring rules (like CRPS), both regimes live on the exact same family of predictors—accessible simply by dialing $\nu$ from 9 to 25.

Key Results

Across all tasks, standard baselines are severely overconfident out of the box, requiring post-hoc temperature scaling that bloats their prediction intervals. SA achieves strong calibration natively while staying remarkably sharp:

Figure 2: Native uncertainty on TimesFM (ETTh1, horizon H=96, series HUFL, S=100 samples) on a test window. SA achieved empirical coverage of 89.6%, closer to the 95% target than any of the baselines (IVON 30.2%, SWAG 13.5%, MultiSWAG 22.9%, Contextual Dropout 72.9%, HSA 7.3%). SA is closest to the 95% target across all 665 test windows in this configuration (mean coverage: 87.8%). Full results across all eight ETT configurations are in Appendix E.
  • TimesFM (ETT): On ETTh1, native SA hits 87.8% mean coverage (target: 95%), whereas native baselines manage just 4–34% (and 73% for Contextual Dropout). Even after baselines are rescued by temperature scaling, SA maintains tighter intervals across all eight configurations.
  • ClimaX Weather Forecasting: Evaluated over 20 splits, native SA achieves a calibration error (Wasserstein distance $W_1$, lower is better) of 0.047, beating four of five baselines even after they receive post-hoc temperature scaling (0.068–0.106). At the same time, SA produces the sharpest prediction intervals (672 $\text{m}^2\text{s}^{-2}$ vs. 932–2453 $\text{m}^2\text{s}^{-2}$ for baselines).
  • Massive Speedups: Preparing MultiSWAG on ClimaX takes 11.9 days of GPU compute, and SWAG takes 28.6 hours. Tuning SA on the frozen backbone takes 3 minutes—nearly three orders of magnitude faster—with at most an 11% per-pass inference overhead.
Calibration histograms on ClimaX showing near-uniform native calibration for SA.
  • UCI Regression: SA achieves the best native calibration on 6 of 8 datasets and the narrowest intervals on 7 of 8, performing strongest when the underlying deterministic backbone is highly accurate.

Limitations and Future Work

The authors highlight two clear boundaries to their approach:

  • A Single Global Knob: Sharing one $\nu$ across every head and layer limits expressivity. Assigning layer-wise or head-wise parameters could capture richer uncertainty patterns, though at higher calibration cost.
  • Continuous Targets Only: The current dispersion-matching calibration loss relies on Euclidean residuals tailored for regression and forecasting; extending SA to classification or discrete structured outputs will require designing new residual objectives.

Finally, because SA only randomizes internal routing rather than model weights, the authors note it could be paired with weight-space methods in the future to better capture deep epistemic uncertainty under distribution shifts.

Summary updated

Abstract

Transformer-based scientific foundation models are increasingly deployed in high-stakes settings, but current architectures give deterministic outputs and provide limited support for calibrated predictive uncertainty. We propose Stochastic Attention, a lightweight sample-average inference-time modification that randomizes attention by replacing softmax weights with normalized multinomial samples controlled by a single concentration parameter, and produces predictive ensembles without retraining. To set this parameter, we introduce a calibration objective that matches the stochastic attention output with the target, yielding an efficient univariate post-hoc tuning problem. We evaluate this mechanism on scientific foundation models for weather and time-series forecasting, as well as a regression task. Across benchmarks against baseline methods, Stochastic Attention achieves the strongest native calibration and the sharpest prediction intervals at comparable calibration, with adaptation costs nearly three orders of magnitude lower than the next-best baseline. Code is available at https://github.com/UQUH/StochasticAttention.
BibTeX
@inproceedings{yadav2026calibrating,
  author = {Akash Yadav and Taiwo Adebiyi and Ruda Zhang},
  title = {{Calibrating Scientific Foundation Models with Inference-Time Stochastic Attention}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=ILRMadoCwR},
}
Figure