Inferensys

Glossary

Temperature Scaling

A post-hoc calibration method that divides the logits by a single scalar parameter to soften the softmax output without changing the model's accuracy.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
POST-HOC CALIBRATION

What is Temperature Scaling?

Temperature scaling is a post-hoc calibration method that adjusts a model's confidence estimates by dividing the output logits by a single scalar parameter, softening the softmax distribution without altering the model's hard classification accuracy.

Temperature scaling is a simple yet effective technique for confidence calibration that introduces a single parameter, T > 0, to the softmax function. By computing softmax(logits / T), the method smooths the predicted probability distribution when T > 1, reducing overconfidence. Crucially, because the softmax function is monotonic, the relative ranking of class probabilities—and thus the model's accuracy—remains unchanged.

The optimal temperature T is learned by minimizing the Negative Log-Likelihood (NLL) on a held-out validation set, distinct from the training data. This parameterization prevents overfitting to the training loss. When T = 1, the original model probabilities are recovered; T < 1 sharpens the distribution, while T > 1 produces a softer, better-calibrated output that aligns predicted confidence with the empirical likelihood of correctness.

POST-HOC CALIBRATION

Key Characteristics of Temperature Scaling

Temperature scaling is a simple yet highly effective technique for calibrating neural network confidence. It uses a single scalar parameter to soften the softmax output without affecting the model's accuracy or rank order.

01

Single Scalar Parameter

Temperature scaling introduces exactly one parameter (T > 0) that divides all logits before the softmax function. This is the simplest form of Platt scaling for multi-class problems.

  • T = 1: The original, uncalibrated model output
  • T > 1: Softens probabilities, reducing overconfidence
  • T < 1: Sharpens probabilities, increasing confidence peaks

The parameter is learned by minimizing the Negative Log-Likelihood (NLL) on a held-out validation set, completely separate from the training data.

02

Accuracy-Preserving Transformation

A critical property of temperature scaling is that it is a monotonic transformation of the logits. Because the temperature parameter divides all logits equally, the relative ordering of class probabilities never changes.

  • The argmax prediction remains identical before and after scaling
  • Top-k accuracy is completely unaffected
  • Only the confidence values associated with predictions are adjusted

This makes it safe to apply to production models without any risk of degrading classification performance.

03

Overconfidence Mitigation

Modern deep neural networks are notoriously miscalibrated, often producing confidence scores that are systematically higher than their actual accuracy. Temperature scaling directly addresses this.

  • A model might predict a class with 95% confidence but only be correct 80% of the time
  • By learning T > 1, the probability mass is spread more evenly across classes
  • The resulting probabilities better reflect the empirical frequency of correctness

This is essential for high-stakes applications where a calibrated "I don't know" is more valuable than an overconfident error.

04

Validation Set Optimization

The optimal temperature T is found by optimizing a proper scoring rule on a dedicated calibration set. This set must be distinct from both the training data and the final test data to avoid biased estimates.

  • Objective: Minimize NLL on the calibration set
  • Optimizer: Typically L-BFGS or simple grid search since there is only one parameter
  • Data Size: A few thousand samples are usually sufficient

The learned T generalizes well because it captures the global tendency of the model to be overconfident or underconfident.

05

Comparison to Other Calibration Methods

Temperature scaling occupies a sweet spot between complexity and effectiveness in the calibration landscape.

  • vs. Histogram Binning: Temperature scaling is parametric and smoother, avoiding discontinuous probability jumps
  • vs. Isotonic Regression: Much less prone to overfitting on small calibration sets
  • vs. Bayesian Methods: Computationally trivial, requiring no multiple forward passes or weight distributions
  • vs. Ensemble Methods: Does not require training multiple models

For most practical applications, temperature scaling is the recommended baseline before exploring more complex approaches.

06

Limitations and Failure Modes

Despite its elegance, temperature scaling has important limitations that practitioners must understand.

  • Global parameter: A single T cannot correct class-specific or input-dependent miscalibration patterns
  • No effect on ranking: Cannot fix cases where the model confidently predicts the wrong class
  • Underconfidence: If the model is already underconfident, T < 1 can amplify noise
  • Out-of-distribution: Does not help detect inputs far from the training distribution; the model may still be confidently wrong

For these scenarios, consider matrix scaling (per-class temperatures) or vector scaling as extensions.

POST-HOC CALIBRATION COMPARISON

Temperature Scaling vs. Other Calibration Methods

A comparison of temperature scaling against other common post-hoc calibration techniques for neural network classifiers.

FeatureTemperature ScalingPlatt ScalingIsotonic RegressionHistogram Binning

Parametric form

Single scalar T

Logistic regression

Non-parametric

Non-parametric

Number of parameters

1

2

N/A

N (bin edges)

Preserves accuracy rank

Requires held-out calibration set

Risk of overfitting on small sets

Handles multi-class natively

Expected Calibration Error (ECE) reduction

High

Moderate

Very High

Moderate

Computational cost at inference

Negligible

Negligible

Low

Negligible

Temperature Scaling

Frequently Asked Questions

Clear, technical answers to the most common questions about temperature scaling, a critical post-hoc calibration method for aligning model confidence with empirical accuracy.

Temperature scaling is a post-hoc calibration method that adjusts a model's predicted probabilities by dividing the output logits by a single scalar parameter, T (temperature), before applying the softmax function. When T > 1, the softmax output is softened, reducing the confidence of overconfident predictions without altering the model's accuracy or the rank order of predictions. The optimal temperature is learned by minimizing the negative log-likelihood on a held-out validation set, making it a simple yet effective technique for correcting miscalibrated neural networks.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.