Calibration Attention: Instance-wise Temperature Scaling for Vision Transformers

Wenhao Liang, Wei Emma Zhang, Lin Yue, Miao Xu, Olaf Maennel, Weitong Chen · Submission to ICLR 2026 · Withdrawn

TL;DR

Standard temperature scaling tunes a single global scalar to fix neural network confidence, but it fails to capture per-instance difficulty and degrades under distribution shift. Calibration Attention (CalAttn) adds a lightweight (<0.1% parameters) two-layer MLP to Vision Transformers that reads the [CLS] embedding and dynamically predicts an instance-specific temperature, cutting Expected Calibration Error (ECE) by over 50% without altering top-1 accuracy.

What Problem Does This Paper Address?

Modern Vision Transformers (ViTs) achieve impressive accuracy, but their predicted probabilities are often severely miscalibrated—models tend to be wildly overconfident when wrong, or underconfident on simple instances.

The standard fix is post-hoc temperature scaling (TS), which divides all pre-softmax logits by a single constant $T^*$ learned on a validation set. However, uncertainty in real-world data is heteroscedastic (sample-dependent):

  • Easy examples need different adjustments than hard, ambiguous examples.
  • Under distribution shift, a single global $T^*$ over-cools straightforward inputs and under-cools challenging ones.
  • Post-hoc scaling cannot pass calibration gradients back to the model’s internal representations during training.

Methods

CalAttn introduces an end-to-end, instance-adaptive temperature head integrated into standard ViT training:

  • Architecture: A lightweight two-layer MLP ($d \to h \to 1$, with $h=128$, GELU, and Softplus activation) that reads the final classification token ($z_{\text{CLS}}$) and predicts a positive scale $s(z) > 0$.
  • Rank-Preserving Rescaling: Logits are scaled as $\tilde{\ell} = \ell / s(z)$ before passing to softmax. Because $s(z)$ is a single positive scalar per sample, it preserves class order and does not degrade top-1 classification accuracy.
  • Initialization: Biases are initialized so $s(z) \approx 1$ at step zero, ensuring training begins identically to standard baselines.
  • Joint Loss Function: Trained jointly with the transformer backbone using cross-entropy paired with a differentiable Brier score penalty: $$\mathcal{L} = \mathcal{L}_{\text{CE}} + \lambda \|\hat{y} - e_y\|_2^2 \quad (\text{with } \lambda = 0.1)$$ The Brier score acts as a differentiable proxy for Expected Calibration Error, producing gradients that push $s(z)$ higher on overconfident errors and lower on underconfident correct predictions.
CLS Vector ──► [FC ──► GELU ──► FC ──► Softplus] ──► Temperature s(z)
                                                            │
Logits ℓ ─────────────────────────────────────────── [ ÷ s(z) ] ──► Softmax

Datasets

The authors benchmarked across multiple classification tasks:

  • Standard In-Distribution: CIFAR-10, CIFAR-100, MNIST, Tiny-ImageNet (200 classes), and ImageNet-1K.
  • Out-of-Distribution (OoD) Shifts: SVHN and CIFAR-10-C (corruptions) to test robustness against covariate and semantic shift.
  • No new benchmarks were created; established benchmarks were utilized.

Key Insights and Ideas

  • The [CLS] token acts as an intrinsic "thermometer": The $\ell_2$ norm $\|z_{\text{CLS}}\|_2$ moderately correlates with model confidence and sample difficulty (Pearson $r \approx 0.45$). ViTs naturally embed difficulty geometry; CalAttn simply learns to map that geometric cue into temperature space.
  • Three distinct training phases:
  • Global alignment (epochs 0–30): CalAttn quickly mirrors a global scalar $T^*$, collapsing variance across instances.
  • Selective sharpening (epochs 30–150): The scale settles near or below 1.0, sharpening underconfident classes that global TS overlooks.
  • Heteroscedastic adaptation (epochs 150–350): Once the backbone converges, the coefficient of variation in $s(z)$ rises sharply (to $\approx 0.18$), assigning tailored cooling to overconfident outliers and mild sharpening to underconfident ones.
  • Pooling strategies matter: For standard ViTs and DeiT, feeding the average of spatial patch tokens to CalAttn often outperforms using the [CLS] token alone (e.g., cutting CIFAR-100 ECE from 6.87% to 4.38% on DeiT-S). For hierarchical architectures like Swin, the global average pooled token remains optimal.

Key Results

  • Calibration Gains: Across CIFAR-10/100, MNIST, Tiny-ImageNet, and ImageNet-1K on ViT-224, DeiT-Small, and Swin-Small, CalAttn reduced ECE by an average of 2.02 percentage points (57.2%) pre-temperature scaling and 1.18 pp (56.6%) post-temperature scaling.
  • ImageNet-1K Scalability: On Swin-S, CalAttn reduced ECE from 4.95% (CE+Brier) down to 1.25% (a 75% relative drop) and decreased adaptive ECE (AECE) by 20%, maintaining top-1 accuracy at 79.68%.
  • Suppressing High-Confidence Errors: CalAttn reduced high-confidence false positives ($\text{confidence} > 0.90$) by 18% to 71% across CIFAR-100 backbones while slightly improving AUROC.
  • Negligible Overhead: Adds fewer than $0.1\%$ additional parameters (roughly 0.19–0.38 MB per checkpoint).

Limitations and Future Work

  • Dependency on Global Token Representations: CalAttn relies on a unified global summary token (like [CLS] or global average pooling). Applying it to convolutional networks or dense prediction tasks requires different pooling design choices.
  • Task Scope: The current evaluation is restricted to standard multi-class image classification; performance in structured prediction (dense segmentation, object detection) or vision-language models remains open for exploration.
  • Ablation with Heavy Concatenation: Naively concatenating patch-mean vectors with the [CLS] token doubled input dimensions and caused overfitting on ViT-224 (ECE jumped to 11.56%), highlighting that the head must remain compact and regularized.

Summary updated

BibTeX
@misc{liang2025calibration,
  author = {Wenhao Liang and Wei Emma Zhang and Lin Yue and Miao Xu and Olaf Maennel and Weitong Chen},
  title = {{Calibration Attention: Instance-wise Temperature Scaling for Vision Transformers}},
  year = {2025},
  eprint = {2508.08547},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.08547},
}
Figure