Temperature scaling is a calibration technique that divides the logits of a neural network by a scalar parameter T before applying the softmax function. A high temperature (T > 1) softens the probability distribution, making class probabilities more uniform and exposing the relative similarities between incorrect classes—the dark knowledge—while T = 1 recovers the standard softmax.
Glossary
Temperature Scaling

What is Temperature Scaling?
A hyperparameter applied to the softmax function that controls the entropy of the output probability distribution, revealing the 'dark knowledge' of a model's internal representations.
In knowledge distillation, a teacher model's softened outputs serve as soft targets for training a student model, providing richer supervisory signals than hard labels. The temperature is critical during training but set to 1 at inference. This mechanism is also used for model calibration, reducing overconfidence by aligning predicted probabilities with empirical accuracy.
Key Characteristics of Temperature Scaling
Temperature scaling is a hyperparameter applied to the softmax function that controls the entropy of the output probability distribution, revealing the 'dark knowledge' of a model's internal representations.
Softmax with Temperature Parameter
Temperature scaling modifies the standard softmax function by dividing logits by a scalar T before exponentiation. When T = 1, the function behaves as standard softmax. As T → ∞, the distribution approaches uniform, making all classes equally probable. As T → 0, the distribution becomes a Dirac delta at the argmax, outputting hard labels. The formula is: softmax(z_i / T) = exp(z_i / T) / Σ_j exp(z_j / T). This single scalar parameter is applied identically across all classes, preserving the rank order of the original logits while adjusting the confidence of the prediction.
Dark Knowledge Extraction
The term dark knowledge refers to the information encoded in the relative probabilities of incorrect classes within a teacher model's softmax output. At high temperatures, the softmax surface reveals inter-class similarities that are obscured at T=1. For example, a model classifying a handwritten '3' might assign a probability of 10⁻⁶ to '8' and 10⁻⁹ to 'dog' at T=1. With temperature scaling, these differences are magnified, showing that '3' is semantically closer to '8' than to 'dog'. This structural knowledge about the data manifold is transferred to the student during distillation.
Distillation Loss Weighting
During knowledge distillation, the student model is trained with a composite loss function that balances two objectives. The distillation loss uses the Kullback-Leibler divergence between the student's soft targets and the teacher's soft targets, both computed with the same high temperature T. The student loss is the standard cross-entropy between the student's predictions at T=1 and the ground-truth hard labels. A weighting parameter α (typically 0.1 to 0.5) controls the relative contribution of these two losses: L_total = α * L_hard + (1 - α) * T² * L_soft. The T² scaling factor is applied to keep gradient magnitudes consistent.
Post-Training Calibration
Beyond distillation, temperature scaling serves as a post-hoc calibration method for modern neural networks. Unlike Platt scaling or isotonic regression, temperature scaling does not change the model's accuracy or the rank ordering of predictions—it only adjusts confidence estimates. A single scalar T is optimized on a held-out validation set to minimize the negative log-likelihood or expected calibration error (ECE). This technique is particularly effective for calibrating large language models and deep ensembles, where overconfident predictions are a well-documented problem. The optimal T is found via gradient descent on the calibration metric.
Entropy and Gradient Flow
Temperature scaling directly controls the entropy of the softmax distribution, which in turn affects the gradient flow during backpropagation. At low temperatures, gradients are sparse—only the top class receives a meaningful signal. At high temperatures, the gradient is distributed more evenly across classes, providing richer training signals for the student. However, excessively high temperatures can drown the signal in noise. Empirical studies show optimal distillation temperatures typically range from T=2 to T=20, depending on the number of classes and the complexity of the teacher model. The choice of T represents a bias-variance tradeoff in the transferred knowledge.
Logit Matching Equivalence
An important theoretical property of temperature scaling is its relationship to logit matching. When the distillation loss uses KL divergence with a high temperature T and the soft targets are derived from the teacher's logits, the gradient of the distillation loss with respect to the student's logits approaches a simple squared error between the student and teacher logits as T → ∞. Specifically, the gradient becomes proportional to (z_student - z_teacher) / T. This reveals that high-temperature distillation is asymptotically equivalent to directly matching the logit vectors of the teacher, providing a simpler interpretation of what the student is learning.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the temperature hyperparameter and its role in softening probability distributions during knowledge distillation.
Temperature scaling is a hyperparameter applied to the softmax function that controls the entropy of the output probability distribution. By dividing the logits by a temperature parameter ( T ), the model's confidence is modulated: a higher ( T > 1 ) produces a softer, more uniform distribution, while ( T < 1 ) sharpens it toward a one-hot vector. Mathematically, the scaled softmax is defined as:
codesoftmax(z_i / T) = exp(z_i / T) / Σ_j exp(z_j / T)
This mechanism is the cornerstone of knowledge distillation, where it reveals the dark knowledge encoded in the relative probabilities of incorrect classes. Unlike calibration-focused temperature scaling, distillation uses high temperatures during both teacher inference and student training to expose the inter-class similarity structure learned by the teacher.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Temperature Scaling vs. Other Calibration Methods
A technical comparison of temperature scaling against alternative probability calibration techniques for neural network outputs.
| Feature | Temperature Scaling | Platt Scaling | Isotonic Regression | Histogram Binning |
|---|---|---|---|---|
Parametric form | Single scalar T > 0 | Logistic regression on logits | Non-parametric step function | Piecewise constant bins |
Number of parameters | 1 | 2 (A, B) | N/A (data-driven) | M bins |
Preserves rank order | ||||
Optimization objective | NLL on validation set | NLL on validation set | Isotonic NLL minimization | Bin-wise accuracy matching |
Prevents overfitting on small sets | ||||
Applicable to multi-class | ||||
Typical ECE reduction | 70-90% | 50-70% | 60-85% | 30-50% |
Computational cost | O(1) post-training | O(N) convex optimization | O(N log N) PAVA algorithm | O(N) bin assignment |
Related Terms
Temperature scaling is a critical hyperparameter that unlocks the 'dark knowledge' within a teacher model. Explore the core concepts that interact with this softening mechanism.
Soft Targets
The probability distributions over classes produced by a teacher model, typically smoothed by a high temperature parameter. These provide richer information about inter-class similarities than hard labels.
- A soft target might show a 'cat' image as 90% cat, 9% dog, 1% car.
- This reveals the teacher's learned structure that a cat is more similar to a dog than a car.
Dark Knowledge
The implicit information about the generalization and similarity structure of the data encoded in the relative probabilities of incorrect classes within a teacher's softmax output.
- This knowledge is invisible in hard labels but becomes apparent when temperature scaling softens the distribution.
- It teaches the student how the teacher generalizes, not just what it predicts.
Kullback-Leibler Divergence
A statistical measure of how one probability distribution diverges from a second, reference distribution. It is used as the primary loss component to align student outputs with teacher soft targets.
- Minimizing the KL divergence forces the student to match the teacher's softened probability distribution.
- Often combined with standard cross-entropy loss against ground-truth labels.
Distillation Loss
A composite objective function that combines the Kullback-Leibler divergence between teacher and student soft targets with the standard cross-entropy loss against ground-truth labels.
- The KL term transfers dark knowledge.
- The cross-entropy term ensures the student still learns from real data.
- A weighting hyperparameter balances these two objectives.
Knowledge Distillation
A model compression technique where a smaller 'student' model is trained to replicate the behavior and predictive performance of a larger, more complex 'teacher' model.
- Temperature scaling is the key mechanism that controls the softness of the teacher's output distribution.
- The student learns to mimic the teacher's generalization, not just its final predictions.
Model Calibration
The process of aligning a model's predicted confidence scores with its empirical accuracy. Temperature scaling is a widely used post-hoc calibration method.
- A single scalar parameter T is learned on a validation set to rescale logits.
- With optimal T, a prediction of 80% confidence should be correct exactly 80% of the time.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us