Temperature scaling is a hyperparameter technique in knowledge distillation where a temperature parameter (T > 1) is applied to the softmax function of the teacher model's logits to produce a smoother, more informative probability distribution for the student to learn from. This softened distribution, rich in dark knowledge about inter-class similarities, provides a superior training signal compared to hard one-hot labels, enabling the smaller student model to better mimic the teacher's generalization behavior.
Glossary
Temperature Scaling

What is Temperature Scaling?
Temperature scaling is a critical hyperparameter technique in knowledge distillation that modifies the softmax function to produce a more informative training signal for a student model.
The technique directly optimizes the distillation loss, typically the Kullback-Leibler divergence, between the teacher's and student's softened outputs. During inference, the temperature is set back to 1, restoring standard probability calibration. It is a foundational component in creating efficient models like DistilBERT and TinyBERT, bridging the performance gap between large teacher models and compact, deployable student networks.
Key Characteristics of Temperature Scaling
Temperature scaling is a hyperparameter technique in knowledge distillation where a temperature parameter (T > 1) is applied to the teacher model's softmax function to produce a smoother, more informative probability distribution for the student to learn from.
The Temperature Parameter (T)
The temperature parameter (T) is a scalar value applied within the softmax function to control the sharpness of the output probability distribution. The modified softmax function for a logit vector z is: softmax(z_i) = exp(z_i / T) / Σ_j exp(z_j / T). When T = 1, it's the standard softmax. When T > 1, probabilities are 'softened,' making the distribution smoother and less confident. This reveals the dark knowledge—the relative similarities between classes—that the student model learns from.
Softening the Teacher's Outputs
The primary function of temperature scaling is to generate soft targets or soft labels. For example, in an image of a '7', a teacher might output logits leading to hard probabilities like [Cat: 0.01, Dog: 0.02, Seven: 0.95, Nine: 0.02]. With T=3, this becomes a softer distribution like [Cat: 0.05, Dog: 0.10, Seven: 0.70, Nine: 0.15]. This indicates to the student that a '7' is somewhat similar to a '9', but not to a 'cat'—information absent in the one-hot label. This richer signal is the core of effective distillation.
Impact on the Distillation Loss
Temperature scaling is directly integrated into the distillation loss, typically the Kullback-Leibler (KL) Divergence Loss. The student is trained to minimize the divergence between its own softened outputs (using the same T) and the teacher's softened outputs. The total loss is often a weighted sum: L_total = α * L_CE(hard_labels) + (1-α) * T^2 * L_KL(teacher_soft_targets || student_soft_targets). The T^2 term is used to scale the gradients, as the softened probabilities produce smaller gradients magnitude as T increases.
Calibration and Confidence
Beyond distillation, temperature scaling (with T tuned on a validation set) is a premier post-hoc calibration technique. A well-calibrated model's predicted confidence aligns with its accuracy. A model might be accurate but overconfident (e.g., predicting 0.99 probability when it's only correct 80% of the time). Applying T > 1 can smooth its output distribution, reducing confidence on average and improving metrics like Expected Calibration Error (ECE) without retraining the model's weights.
Relationship to Other Distillation Methods
Temperature scaling is often used in conjunction with other distillation paradigms:
- Logit-based Distillation: It is the foundational technique here.
- Feature-based Distillation (e.g., Attention Transfer): Temperature is not typically applied to intermediate features.
- Online Distillation: The temperature parameter can be applied to the peer models' outputs.
- Quantization-Aware Distillation (QAD): Temperature-scaled soft targets can help the student model learn a more robust representation before quantization. It is a complementary, not competing, technique.
Practical Tuning and Considerations
Choosing the right temperature is critical. Common practices include:
- Typical Range: T is usually between 1 and 20, with 3-5 being a common starting point for vision and NLP tasks.
- Tuning: T is a hyperparameter validated on a downstream task's performance. Too low (≈1) provides little dark knowledge. Too high flattens the distribution excessively, losing necessary discriminative signal.
- Inference: The temperature is only used during the student's training. During final inference, the student model uses the standard softmax (T=1). The teacher's role, and thus temperature scaling, is complete.
Effect of Temperature Parameter (T) on Output
How adjusting the temperature scaling hyperparameter (T) modifies the teacher model's softmax output distribution, which serves as the training target for the student model.
| Output Characteristic | Low Temperature (T → 0+) | Standard Temperature (T = 1) | High Temperature (T > 1) |
|---|---|---|---|
Probability Distribution Shape | Approaches one-hot encoding | Standard softmax | Softer, more uniform distribution |
Peak Probability Value | ~1.0 | Model-dependent (e.g., 0.9) | Lower (e.g., 0.7) |
Information Content (Entropy) | Very Low | Model-dependent | Higher |
Inter-Class Similarity Signal (Dark Knowledge) | Minimal | Present | Amplified |
Primary Use Case | Standard classification (not for KD) | Baseline teacher output | Optimal for knowledge distillation |
Gradient Signal for Student | Sparse, high-variance | Balanced | Denser, smoother |
Risk of Overfitting Student | High | Medium | Low |
Typical Value Range in KD | 2.0 to 10.0 |
Frequently Asked Questions
Temperature scaling is a critical hyperparameter in knowledge distillation that modifies the softmax function to create a more informative training signal for a student model.
Temperature scaling is a hyperparameter technique used primarily in knowledge distillation to soften the output probability distribution of a teacher model by dividing its logits by a temperature parameter (T > 1) before applying the softmax function. This process produces soft targets that contain richer inter-class similarity information, known as dark knowledge, which a student model can learn from more effectively than from hard one-hot labels. The technique is foundational because it reveals the relative confidence the teacher has between similar classes (e.g., between different breeds of dog), providing a more nuanced training signal.
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.
Related Terms
Temperature scaling is a core hyperparameter in knowledge distillation. These related terms define the ecosystem of techniques, models, and loss functions that enable efficient knowledge transfer from large teacher models to compact student models.
Knowledge Distillation (KD)
Knowledge Distillation (KD) is the overarching model compression technique where a smaller student model is trained to mimic the predictive behavior of a larger, pre-trained teacher model. The primary mechanism is for the student to learn from the teacher's softened output probabilities (soft targets), which contain richer inter-class similarity information (dark knowledge) than hard one-hot labels. This process enables the deployment of high-accuracy models in resource-constrained environments.
- Core Objective: Transfer 'dark knowledge' from teacher to student.
- Key Components: Teacher model, student model, distillation loss function.
- Primary Use Case: Model compression for efficient inference.
Soft Targets / Soft Labels
Soft targets, or soft labels, are the probability distributions output by a teacher model's final softmax layer (often with temperature scaling applied). Unlike hard one-hot labels (e.g., [0, 0, 1, 0]), soft targets (e.g., [0.01, 0.04, 0.9, 0.05]) encode the teacher's relative confidence across all classes, capturing dark knowledge about inter-class similarities. These are the primary learning signal for the student model in knowledge distillation.
- Contain Dark Knowledge: Reveal which classes the teacher considers 'similar'.
- Generated via Softmax: Applied to the teacher's logits.
- Critical for KD: Student minimizes the difference between its outputs and these soft targets.
Kullback-Leibler Divergence Loss (KL Divergence Loss)
Kullback-Leibler Divergence Loss is the standard mimicry loss function used in knowledge distillation. It measures the statistical distance between the softened output probability distributions of the teacher model and the student model. The student is trained to minimize this divergence, forcing its predictions to align with the richer probability distribution of the teacher. It is typically combined with the standard cross-entropy loss in a weighted sum to form the total distillation loss.
- Measures Distribution Similarity: Quantifies how one probability distribution differs from another.
- Core of Distillation Loss: The term that enforces mimicry of the teacher's soft targets.
- Asymmetric: KL(P_teacher || P_student) is not the same as KL(P_student || P_teacher); the former is standard.
Logits
In the context of knowledge distillation, logits are the unnormalized, real-valued output vectors from the final linear layer of a neural network, preceding the softmax activation. They represent the model's raw scores for each class. During distillation, the teacher model's logits are scaled by a temperature parameter (T > 1) before being passed through the softmax function to produce the soft targets. The student model is trained to produce logits that, when similarly scaled and softened, match the teacher's distribution.
- Raw Model Outputs: Pre-softmax classification scores.
- Input to Softmax: Transformed into probabilities.
- Scaled by Temperature: T > 1 smoothes the resulting probability distribution for distillation.
Teacher Model
A teacher model is a large, pre-trained, and typically high-accuracy neural network (e.g., BERT, ResNet-50) whose knowledge is transferred to a smaller student model during knowledge distillation. The teacher acts as a source of dark knowledge, providing soft targets from its output logits and, in feature-based distillation, intermediate feature representations or attention maps. The teacher is usually frozen during the distillation process.
- Source of Knowledge: Provides the training signal for the student.
- Often a SOTA Model: Chosen for its high performance on the target task.
- Frozen Parameters: Its weights are typically not updated during student training.
Student Model
A student model is a smaller, more efficient neural network (e.g., DistilBERT, TinyBERT) that is trained to replicate the performance of a larger teacher model through knowledge distillation. The student's architecture is designed for lower computational and memory footprint, enabling faster inference. It learns by minimizing a distillation loss that aligns its softened outputs with the teacher's soft targets, often while also minimizing standard cross-entropy loss with ground-truth labels.
- Target of Compression: The model intended for efficient deployment.
- Learns via Mimicry: Trained on teacher soft targets, not just hard labels.
- Optimized for Efficiency: Has fewer parameters, layers, or lower precision than the teacher.

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