Temperature Scaling in Neural Networks
- Temperature scaling is a recalibration method that rescales logits using a positive scalar to adjust confidence while preserving hard predictions.
- It fits a single temperature parameter via minimizing the negative log-likelihood on a validation set, leading to improved NLL and ECE measurements.
- Variants of TS extend its application to adaptive and out-of-domain calibration, though its uniform scaling may struggle under severe distribution shifts.
Temperature scaling (TS) denotes the rescaling of logits by a positive scalar before the softmax. In classification, it is a post-hoc calibration method: the trained model weights are held fixed, logits are divided by a temperature , and the resulting probabilities are used to better align confidence with correctness while preserving the hard prediction. In language-model and reinforcement-learning settings, the same transformation is also used to control output sharpness, entropy, and sampling behavior, although its sequence-level effects differ from its classifier-calibration role (Mattei et al., 16 Feb 2026, Mozafari et al., 2019).
1. Mathematical definition and invariant properties
Let be the logits of a -class model. Temperature scaling replaces the standard softmax by
Equivalently, with inverse temperature ,
For , one recovers the base model; for , the distribution softens; for , it sharpens. Because multiplying logits by a positive scalar preserves their ordering, TS does not change the hard prediction ; in this sense it is accuracy-preserving for the classifier’s decision rule (Mattei et al., 16 Feb 2026).
The theory in "The Well-Tempered Classifier" gives three elementary properties. First, increasing temperature increases uncertainty in a very general sense. In particular, if 0 is the tempered classifier, then the Shannon entropy satisfies
1
so entropy decreases in 2 and therefore increases in 3. The same work further states a majorization result: if 4, then 5 majorizes 6, implying monotonic behavior for Schur-concave uncertainty measures. Second, TS admits a geometric characterization: among distributions on the simplex with a prescribed entropy, the one minimizing 7 is exactly a temperature-scaled version of 8. Third, among linear post-hoc scalers such as matrix scaling and Dirichlet calibration, TS is the only linear family that does not change the hard predictions (Mattei et al., 16 Feb 2026).
These results clarify why TS occupies a special position among post-hoc recalibrators. It is not merely a heuristic softmax flattening; it is a one-parameter submodel with a precise entropy monotonicity, an information-projection interpretation, and a unique accuracy-preserving status within linear scaling families (Mattei et al., 16 Feb 2026).
2. Fitting the temperature and measuring calibration
Standard TS uses a labeled validation set 9 that is disjoint from weight training. The network weights are frozen, and 0 is chosen by minimizing the negative log-likelihood (NLL),
1
or, in equivalent notation,
2
Because this is a single-parameter optimization, the cited works describe it as convex or strictly convex and solvable by simple line search, gradient-based methods, L-BFGS, or simple gradient descent initialized at 3 (Mozafari et al., 2019, Chanda et al., 29 Sep 2025).
A common external calibration metric is expected calibration error (ECE). With 4 confidence bins 5,
6
where 7 is the empirical accuracy in bin 8 and 9 is the mean confidence. The definition operationalizes the ideal calibration condition 0: a perfectly calibrated classifier has confidence frequencies matching empirical correctness frequencies at each confidence level (Mozafari et al., 2019).
The workflow is correspondingly simple. One carves out a held-out calibration split, fits 1 solely on that split, and evaluates both predictive metrics and calibration metrics on test data. The medical-imaging study recommends reserving approximately 2 to 3 of the data for temperature tuning, not using test labels for calibration, and using approximately 4 to 5 bins for ECE to avoid extreme sparsity while retaining stable estimates (Chanda et al., 29 Sep 2025).
3. Empirical behavior in deep classifiers
A detailed case study is provided by "Evaluating Temperature Scaling Calibration Effectiveness for CNNs under Varying Noise Levels in Brain Tumour Detection" (Chanda et al., 29 Sep 2025). The model is a light CNN with 4 convolutional blocks followed by 2 fully connected layers and a dropout of 6; inputs are 7, training uses Adam with learning rate 8, batch size 9, and up to 60 epochs with early stopping. The dataset split is 0 training, 1 validation for TS tuning, and 2 testing. To simulate realistic MRI artifacts, five synthetic noise types are applied only to the test set: Gaussian, Poisson, Salt & Pepper, Speckle, and Uniform noise (Chanda et al., 29 Sep 2025).
On clean data, the uncalibrated model attains accuracy 3, NLL 4, and ECE 5. After TS, accuracy remains approximately 6, NLL decreases from 7 to 8, and ECE changes from approximately 9 to 0. Under noise, the reductions are larger. For Gaussian noise with 1 and 2, the uncalibrated model has accuracy 3, NLL 4, and ECE 5; after TS with 6, accuracy is 7 (8), NLL falls to 9, and ECE falls to 0, corresponding to NLL 1 and ECE 2 without meaningful accuracy loss (Chanda et al., 29 Sep 2025).
Across other corruptions, the same pattern recurs. For Poisson noise at scale 3, NLL changes from 4 to 5 and ECE from 6 to 7, with 8. For Salt & Pepper noise with 9 and 0, NLL changes from 1 to 2, ECE from 3 to 4, and 5. Across Uniform and Speckle noise up to scale 6, NLL reductions are 7 and 8, while ECE reductions are 9 for both; 0 ranges from approximately 1 under light noise to approximately 2 under heavier noise. Repeating optimal noise cases on ResNet50 shows the same trend, with Gaussian 3 yielding NLL 4 and ECE 5, and Uniform 6 yielding NLL 7 and ECE 8, while accuracy remains approximately 9 (Chanda et al., 29 Sep 2025).
The reported operational cost is correspondingly small. TS adds only a single scalar optimization step on the validation set, took less than one second on GPU with L-BFGS in those experiments, requires no changes to the model architecture, and does not retrain weights. This makes it attractive whenever the objective is to improve NLL and ECE without altering the learned decision rule (Chanda et al., 29 Sep 2025).
4. Limitations, failure modes, and interaction with conformal prediction
The simplicity of TS is also its principal limitation. Because it rescales confidence uniformly across all samples, it cannot correct class-specific or region-specific miscalibration. The brain-tumour study therefore notes that under severe distribution shift TS may not suffice and suggests adaptive TS variants or full retraining with calibration-aware loss when the shift is strong (Chanda et al., 29 Sep 2025).
A second limitation concerns the calibration set. "Attended Temperature Scaling" shows that the standard TS objective depends directly on labels in the held-out validation set, and identifies two concrete failure modes: small or noisy validation sets, and highly accurate networks. If 0 is small or labels are corrupted, the estimate of 1 can become highly unstable; when a network makes almost no errors on the calibration split, there are too few misclassified examples to pull down overconfidence, so TS can remain sub-optimally calibrated (Mozafari et al., 2018).
A third limitation appears when TS is composed with adaptive conformal prediction. "On Temperature Scaling and Conformal Prediction of Deep Classifiers" reports that TS improves the class-conditional coverage of adaptive CP methods, but negatively affects their prediction-set sizes. For CIFAR-100 with ResNet50 at 2, optimal 3 leaves LAC set size nearly unchanged at 4, but increases APS set size from 5 to 6 and RAPS set size from 7 to 8, while coverage remains approximately 9. The same work proves that APS and RAPS thresholds decrease monotonically with 00, yet the mean set size typically increases, often non-monotonically but with an overall upward trend. Its practical guideline is explicit: do not apply TS before APS or RAPS when the classifier’s top-1 accuracy is below 01, and note that LAC is unaffected in set size because TS preserves the softmax ranking (Dabah et al., 2024).
These limits are not contradictions of the core TS theory. They instead delimit the regime in which a single global temperature is well matched to the structure of the miscalibration problem.
5. Major variants and extensions
A substantial literature generalizes standard TS without abandoning the central idea of logit rescaling. The variants differ primarily in what data are used to fit the temperature and whether the temperature remains global, becomes sample-dependent, or is structured by class, domain, or network depth (Mozafari et al., 2019, Mozafari et al., 2018, Joy et al., 2022, Choi et al., 2024, Guo et al., 2023, Khalifa et al., 2022).
| Variant | Core mechanism | Reported behavior |
|---|---|---|
| UTS | Fit 02 on unlabeled samples via class-wise self-selection | Matches or outperforms TS in NLL and ECE |
| ATS | Attend to borderline examples from other classes | More stable with small or noisy validation sets |
| AdaTS | Predict 03 per sample | Lowers ECE and AdaECE beyond global TS |
| CTS | Add style/content consistency losses | Improves OOD calibration using only source domains |
| Dual-TS | Fuse class-adaptive and equal-size-bin temperatures | Improves calibration in long-tailed recognition |
| LATES | Learn nonnegative weights across layer probes | Improves calibration and also accuracy/AUC |
UTS removes the need for labeled calibration data. It assumes that high-confidence samples for class 04 are likely to come from the true class-05 distribution, constructs sets
06
and minimizes an unsupervised NLL over these pseudo-labeled subsets. On ResNet-110/CIFAR-10, NLL changes from 07 uncalibrated to 08 with TS and 09 with UTS, while ECE changes from 10 to 11 with TS and 12 with UTS. On DenseNet-100/CIFAR-100, NLL changes from 13 to 14 with TS and 15 with UTS, while ECE changes from 16 to 17 with TS and 18 with UTS (Mozafari et al., 2019).
ATS enlarges each class’s calibration subset by including true class-19 samples together with borderline non-20 samples satisfying 21. The reported effect is robustness when the validation set is small or contains noisy labels. On DenseNet40/CIFAR-10, ECE changes from 22 uncalibrated to 23 with TS and 24 with ATS; on ISIC skin-lesion detection with ResNet200, ECE changes from 25 uncalibrated to 26 with TS and 27 with ATS (Mozafari et al., 2018).
AdaTS replaces the single scalar with a predicted 28 for each sample, using a small VAE and an MLP on pseudo-likelihood features. On CIFAR-10 and CIFAR-100, it improves both ECE and AdaECE beyond TS; on CIFAR-10-C, ResNet50 ECE drops from 29 uncalibrated to 30 with TS and 31 with AdaTS (Joy et al., 2022).
CTS is designed for out-of-domain calibration when target-domain validation labels are unavailable. It augments the TS NLL with KL consistency terms under style-shifted and content-shifted feature recombinations. On PACS, Office-Home, Digits-DG, and VLCS, the reported average ECE values for CTS are 32, 33, 34, and 35, compared with 36, 37, 38, and 39 for source-validation TS and 40, 41, 42, and 43 for oracle TS using target labels (Choi et al., 2024).
Dual-TS addresses long-tailed recognition by combining class-adaptive temperatures 44 with equal-size-bin temperatures 45 through
46
On CIFAR-10-LT with imbalance factor 47, Dual-TS reports accuracy 48, ECE 49, and Esbin-ECE 50, versus 51 accuracy and ECE 52 for standard TS. On CIFAR-100-LT with imbalance factor 53, Dual-TS reports accuracy 54, ECE 55, and Esbin-ECE 56, versus 57 accuracy and ECE 58 for TS (Guo et al., 2023).
LATES distributes the scaling operation across all layers by attaching probes after each block and learning a nonnegative weight vector 59 for their logits. On ImageNet with ResNet50, TS reports ECE 60, NLL 61, ACC 62, and AUC 63, whereas LATES reports ECE 64, NLL 65, ACC 66, and AUC 67. Its stated overhead is less than 68 extra parameters, less than 69 extra FLOPs at inference, and less than 70 extra training time (Khalifa et al., 2022).
6. Temperature scaling beyond classifier calibration
Outside standard classifier calibration, TS appears in three closely related but distinct roles. The first is language-model decoding and test-time scaling. The second is entropy restoration in reinforcement learning. The third is token-level recalibration for semantic uncertainty in question answering (Mattei et al., 16 Feb 2026, Wu et al., 2 Oct 2025, Yang et al., 30 May 2026, Lamb et al., 8 Apr 2026).
For autoregressive decoding, token-level temperature rescales next-token logits exactly as in classification. However, "The Well-Tempered Classifier" challenges the common claim that increasing temperature increases diversity for LLMs. A full temperature scaling of the joint autoregressive model is intractable, so practitioners apply a myopic token-level version; in that setting, sequence-level entropy or diversity can be non-monotonic in temperature (Mattei et al., 16 Feb 2026).
At inference time, this does not preclude useful multi-temperature search. "On the Role of Temperature Sampling in Test-Time Scaling" reports that different sampling temperatures solve different subsets of reasoning problems. Averaged over Qwen3 71B, 72B, 73B, and 74B on AIME 2024/2025, MATH500, LiveCodeBench, and Hi-ToM, multi-temperature scaling raises Pass.All from 75 to 76, an additional 77 points over single-temperature TTS. For Qwen3 78B on AIME 2025, performance rises from 79 to 80 (Wu et al., 2 Oct 2025).
In RL from verifiable rewards, TS can be internalized into the model rather than used only at rollout time. TS-OPSD constructs a self-teacher by applying high-temperature scaling to the model’s own logits, then distills that smoother distribution back into the student. On Qwen3-4B, macro-averaged avg@8 and pass@8 change from approximately 81 and 82 for baseline DAPO to approximately 83 and 84 for policy reheating with forward KL; on Qwen3-8B they change from approximately 85 and 86 to approximately 87 and 88. The reported analysis further states that linear CKA between the collapsed and reheated checkpoints remains near 89, while top-90 overlap and overlapping probability mass both exceed 91 (Yang et al., 30 May 2026).
For semantic uncertainty in QA, token-level scalar TS is treated as a post-hoc recalibration method for confidence measures derived from token probabilities. On TriviaQA with Llama-3 and the E-SC measure, ACE changes from 92 at 93 to 94 at 95, while AUROC changes from 96 to 97. On Natural Questions with Qwen-2.5, ACE changes from 98 to 99, while AUROC changes from 00 to 01. The same study argues that a single scalar provides a suitable inductive bias, whereas more expressive token-level recalibration methods can overfit (Lamb et al., 8 Apr 2026).
Taken together, these works show that the phrase “temperature scaling” names a shared logit-rescaling mechanism whose consequences depend strongly on the object being scaled. For classifiers, TS is a one-parameter recalibration that preserves hard predictions and usually improves NLL and ECE. For adaptive prediction sets, domain shift, long-tailed recognition, and sample-specific miscalibration, structured variants modify the fitting procedure or the temperature itself. For LLMs and RL, the same operation governs sharpness and entropy, but its sequence-level and policy-level consequences are not reducible to the standard classifier-calibration picture.