NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Calibrating Transformers via Sparse Gaussian Processes

Wenlong Chen, Yingzhen Li

While Transformer models have revolutionized Natural Language Processing (NLP) and Computer Vision, they suffer from a significant flaw in safety-critical applications: poor calibration. In domains like medical diagnosis or autonomous driving, a model must not only be accurate but also provide a reliable measure of its own confidence. Standard Transformers are often "overconfident" even when they are wrong.

Existing Bayesian methods to fix this, such as Weight-Space Variational Inference, often lead to "underfitting" and lower accuracy. Conversely, Gaussian Processes (GPs)—the "gold standard" for uncertainty estimation—are notoriously difficult to scale to the massive datasets and high-dimensional spaces where Transformers thrive.

To bridge this gap, researchers have developed Sparse Gaussian Process Attention (SGPA), a method that replaces standard Transformer attention with a Bayesian framework. By treating attention as a Sparse Gaussian Process, the model gains the ability to provide reliable uncertainty estimates without sacrificing predictive accuracy.

The SGPA Methodology

The foundation of this work rests on a clever mathematical observation: kernel-based attention is mathematically equivalent to the posterior mean of a Sparse Variational Gaussian Process (SVGP). This implies that standard attention mechanisms are already halfway to being Bayesian; they simply lack the variance (uncertainty) calculation.

Instead of trying to find a distribution over millions of neural network weights (which is computationally prohibitive), SGPA performs Bayesian inference directly on the outputs of the attention blocks. The authors propose two versions of this architecture:

  1. Standard SGPA: This approach directly applies SVGP to multi-head attention. However, it is computationally expensive ($O(T^3)$ time complexity) and memory-intensive because the "inducing points" (the landmarks the GP uses to summarize data) are tied to the input sequence.
  2. Decoupled SGPA: To make the model scalable, the authors introduce an "orthogonally decoupled" approach. They utilize a set of global inducing points shared across all sequences. This allows the model to compute uncertainty independently of the specific input sequence length, bringing the complexity down to a manageable level ($O(BT^2M_g)$) and making it competitive with standard Transformers.

Essentially, SGPA replaces the standard scaled dot-product attention with a valid symmetric kernel (like RBF or Exponential) and propagates uncertainty through every layer of the network.

Comparison of Vanilla Transformer, Standard SGPA, and Decoupled SGPA architectures.

Experimental Evaluation and Key Results

The authors evaluated SGPA across three different modalities: Computer Vision (CIFAR-10/100 using Vision Transformers), NLP (IMDB and CoLA), and Graphs (ZINC). They also tested Out-of-Distribution (OOD) detection using corrupted datasets (CIFAR-10-C, CIFAR-100-C) and entirely different datasets (SVHN, mini-ImageNet).

Unlike previous Bayesian attempts that traded off accuracy for better uncertainty, SGPA-based Transformers often match or even slightly exceed the accuracy of standard models while significantly improving reliability.

Performance comparison on the CoLA dataset.

Key findings include:

  • In-Distribution Calibration: On CIFAR-100, SGPA achieved significantly lower Expected Calibration Error (ECE) and Negative Log-Likelihood (NLL) compared to standard Maximum Likelihood (MLE) and Monte-Carlo Dropout.
  • OOD Robustness: When tested on corrupted images (e.g., blur, noise), SGPA maintained much better calibration as the "skew intensity" increased. In contrast, standard models became wildly overconfident in their errors.
  • OOD Detection: In "in vs. out" detection tasks (e.g., training on CIFAR-10 but testing on SVHN), SGPA ensembles (SGPAE) achieved the best performance, outperforming Deep Ensembles in average AUROC and AUPR ranks.
  • Efficiency: Decoupled SGPA showed a significant reduction in training time and memory compared to the "Standard" SGPA approach, successfully reducing NLL from 1.01 to 0.69 on CIFAR-10.

Limitations and Future Work

While SGPA presents a major step forward for calibrated Transformers, a few challenges remain:

  • Pre-training Compatibility: The current work trains models from scratch. Because SGPA replaces the standard dot-product with a kernel, existing pre-trained weights (like BERT or GPT-3) cannot be easily dropped in. Finding a way to "fine-tune" standard models into SGPA models is a critical next step.
  • Computational Overhead: While the "Decoupled" version is faster than the "Standard" approach, it is still slower than a vanilla Transformer due to the matrix inversions required for the GP.
  • Autoregressive Tasks: The current paper focuses on classification and regression. Adapting this framework to autoregressive generation (like Large Language Models) remains an open challenge.
  • Deep Kernel Inductive Bias: Further research is needed to fully understand the specific "prior" or inductive bias the deep kernel represents compared to standard RBF kernels.

Summary updated

BibTeX
@inproceedings{chen2023calibrating,
  author = {Wenlong Chen and Yingzhen Li},
  title = {{Calibrating Transformers via Sparse Gaussian Processes}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=jPVAFXHlbL},
}
Figure