AI Glossary / AI and machine learning / Intermediate

Temperature Scaling

Definition

Temperature scaling is a method for adjusting a classifier's probability estimates by dividing its logits by a learned positive number before applying softmax. In post-training calibration, that number is fitted using labeled calibration data. The aim is to make reported confidence better match observed correctness, while preserving the class with the largest score.

What it means

A classifier can choose the right category often and still sound too certain. For example, predictions labeled 90% confident may be correct substantially less than 90% of the time. Calibration concerns this agreement across sets of predictions. Temperature scaling changes how concentrated the probability distribution is, without retraining the underlying feature extractor. A temperature above 1 softens probabilities, while a value below 1 sharpens them. The parameter is learned for a defined model and data setting; choosing a pleasing-looking confidence value by hand is not evidence of calibration.

How it works

Keep the trained classifier fixed and obtain its logits on calibration examples that were not used to fit its weights. Choose one positive scalar T to minimize negative log-likelihood of the observed labels after softmax(logits/T). Store T with the model and apply the same transformation to future logits. Because division by the same positive number preserves their ordering, the top-scoring class stays the same, including the ordering of tied scores in exact arithmetic. The method cannot make class-specific or input-specific corrections with its single parameter. Evaluate the resulting probabilities on separate data, using appropriate probability scores and calibration plots rather than only classification accuracy.

Three practical examples

  • An image-labeling service adjusts confidence before deciding which uncertain catalog photos should receive human review. Its decision threshold may need retuning after calibration.
  • A document classifier uses calibrated probabilities when combining several possible categories into a review queue, while preserving the top category for each document.
  • An intent classifier reports confidence to a downstream assistant that can ask for clarification. Calibration supports that routing decision but does not prove that the assistant's eventual answer is correct.

Think of it this way

Think of adjusting the sensitivity of a confidence dial without changing which option the pointer favors. Turning the dial down can reduce excessive certainty, but cannot move the pointer to a different preferred option. The analogy is limited: temperature scaling transforms an entire probability distribution through logits, rather than simply subtracting the same percentage from each confidence score.

Worked example

Suppose a two-class model produces logits (2, 0). At T = 1, the first probability is exp(2)/(exp(2) + 1), approximately 0.8808; the second is 0.1192. With T = 2, the scaled logits are (1, 0), giving probabilities approximately 0.7311 and 0.2689. The first class remains the prediction. If the first class is correct, its negative log-likelihood changes from about 0.1269 to 0.3133, becoming worse for this single example. If the second class is correct, loss changes from about 2.1269 to 1.3133, becoming better. Calibration fits T across the calibration set, balancing such cases rather than demanding that every example improve. These calculations illustrate a chosen temperature; they do not establish that T = 2 is optimal for a real dataset.

Illustrative case study

In a fictional project, Cedar Catalog notices that its image classifier's strongest confidence band contains more mistakes than expected. The team sets aside calibration images, fits a scalar temperature and evaluates on a different set. It compares reliability plots, probability loss and the workload produced by its review threshold. When a new product range arrives, staff check calibration again instead of assuming the old parameter remains appropriate. The case describes an evaluation workflow, not a reported commercial result.

Common misconceptions and mistakes

Do not confuse post-training calibration with changing a language model's sampling temperature for creative generation. Both can divide logits, but their purpose and parameter-selection process differ. Temperature scaling does not fix incorrect top-class rankings or improve top-one accuracy under the stated transformation. Lower confidence is not automatically better calibration, and higher confidence is not automatically worse. A single global temperature can conceal class-specific problems. Distribution shifts, rare categories and small calibration samples can make an apparently good overall plot unreliable for particular users or cases.

Business use

Use temperature scaling when a system already exposes logits and decisions depend on probability quality, not just the winning label. Define a calibration dataset representative of expected use and keep a separate final evaluation. Record the model version, class mapping, fitted temperature and threshold policy together. Review both average probability quality and important subgroups. If a downstream rule changes after recalibration, compare its actual error and review costs. Recheck the calibration when the model, preprocessing or input population changes; a parameter fitted under one setting is not a permanent reliability certificate.

People also ask

Can temperature scaling correct every calibration problem?

No. One scalar cannot represent all class-specific or input-dependent errors.

Will it change the predicted class?

A shared positive temperature preserves the argmax; threshold-based actions can nevertheless change because probabilities change.

Is calibration the same as uncertainty about unfamiliar inputs?

No. Good calibration on a test distribution does not establish reliable behavior on inputs far outside that distribution.

Check your understanding

After temperature scaling, a model chooses exactly the same class for every test example. Does that mean calibration had no effect?

Answer: No. Its probabilities may have changed substantially, affecting probability loss and decisions based on confidence thresholds. Unchanged top-one accuracy is expected for a shared positive temperature.

Related terms

  • Probability calibration
  • Logits
  • Softmax
  • Platt scaling
  • negative log-likelihood
  • reliability diagram

Learn next

calculate softmax for one logit vector at several positive temperatures. Then inspect a reliability diagram and compare negative log-likelihood before and after fitting T on separate calibration data. Keep the final test set outside that fitting process.

  • Log likelihood
  • Test set
  • Softmax

More in AI and machine learning

  • Target network - A target network is a more slowly updated network used to calculate learning targets in some reinforcement-learning methods.
  • Targeted maximum likelihood estimation - Targeted maximum likelihood estimation, or TMLE, is a statistical framework that updates an initial estimate specifically to improve estimation of a chosen...
  • Task decomposition - Task decomposition means dividing a larger goal into smaller, executable tasks.
  • Temporal data - Temporal data is data associated with different points or periods in time.
  • Tensor sketch - Tensor sketch is a randomized technique for representing a large tensor-product feature map with a much smaller vector.
  • Termination condition - A termination condition is a rule that determines when a process stops.

Sources

Sources: Guo and colleagues, On Calibration of Modern Neural Networks, section 4.2, https://proceedings.mlr.press/v70/guo17a/guo17a.pdf ; scikit-learn, probability calibration and temperature scaling, https://scikit-learn.org/stable/modules/calibration.html#temperature-scaling . The paper defines scalar temperature fitting and the preservation of class predictions; numerical examples above are independently calculated illustrations.

Previous: Temperature sampling Next: Template

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer