Inferensys

Glossary

Soft Targets / Soft Labels

Soft targets, or soft labels, are the probability distributions output by a teacher model's final softmax layer, used as the primary learning signal to train a smaller student model in knowledge distillation.
Knowledge engineer constructing knowledge base on laptop, document hierarchy visible, casual office setup.
KNOWLEDGE DISTILLATION

What are Soft Targets / Soft Labels?

In machine learning, particularly knowledge distillation, soft targets are the probabilistic outputs of a teacher model that provide a richer training signal than traditional hard labels.

Soft targets, also called soft labels, are the probability distributions output by a teacher model's final softmax layer, often after applying temperature scaling (T > 1). Unlike hard one-hot labels that assign 100% probability to a single class, these softened distributions encode the teacher's relative confidence across all classes, capturing inter-class similarities and dark knowledge. This richer information serves as the primary learning signal for training a smaller student model.

Using soft targets as the training objective, typically via a Kullback-Leibler Divergence loss, allows the student model to learn the nuanced decision boundaries and generalization patterns of the larger teacher. This is the core mechanism of knowledge distillation, enabling the creation of compact, efficient models that retain much of the teacher's accuracy. The technique is foundational to models like DistilBERT and TinyBERT.

MODEL DISTILLATION

Key Characteristics of Soft Targets

Soft targets are the probability distributions output by a teacher model's final softmax layer, containing richer information than hard labels. They are the primary learning signal in knowledge distillation.

01

Probabilistic Distributions

Unlike hard targets (one-hot encoded vectors), soft targets are full probability distributions over all possible classes. For a classification task with N classes, a soft target is a vector of N values where each value represents the model's confidence that the input belongs to that class. The sum of these probabilities is 1. This format conveys the teacher's uncertainty and relative similarity between classes.

  • Example: For an image of a cat, a hard label is [1, 0, 0] for classes [cat, dog, car]. A corresponding soft target from a well-trained teacher might be [0.85, 0.12, 0.03], indicating the model is highly confident it's a cat, sees some visual similarity to a dog, and is very sure it's not a car.
02

Contain Dark Knowledge

The primary value of soft targets is the dark knowledge they encode. This term, coined by Geoffrey Hinton, refers to the rich, inter-class similarity information learned by the teacher model during training. A one-hot label only tells the student that 'this is a cat.' A soft target additionally conveys that 'this is very much a cat, somewhat similar to a lynx, but not at all like a truck.'

This relational information acts as a powerful regularizer and learning signal, teaching the student the nuanced relationships within the data manifold that the teacher has discovered. It is this dark knowledge that allows a small student model to often match or exceed the performance of training solely on hard labels.

03

Temperature-Scaled

Soft targets are almost always generated using temperature scaling applied to the teacher's logits (pre-softmax activations). The standard softmax function is modified with a temperature parameter T: softmax(logits / T).

  • T = 1: Produces the teacher's normal output distribution.
  • T > 1: 'Softens' the distribution, making it smoother. Probabilities become more uniform, amplifying the differences between non-argmax classes. This makes the dark knowledge more pronounced and easier for the student to learn.
  • T → ∞: Distribution becomes uniform.
  • T < 1: Sharpens the distribution, making it more like a one-hot vector.

A typical value for distillation is T between 2 and 10. During student inference, T is set back to 1.

04

Primary Training Signal

In the canonical knowledge distillation loss function, the soft targets provide the main learning objective. The total loss (L_total) is a weighted sum of two components:

L_total = α * L_hard + (1 - α) * L_soft

  • L_soft: The distillation loss, typically the Kullback-Leibler (KL) Divergence between the student's temperature-scaled soft predictions and the teacher's temperature-scaled soft targets. This term forces the student to mimic the teacher's probability distribution.
  • L_hard: The standard cross-entropy loss with the ground-truth hard labels. This term anchors the student to the true labels.
  • α: A weighting hyperparameter (often small, e.g., 0.1).

This combination allows the student to learn both the correct answer and the teacher's refined understanding of the problem space.

05

Contrast with Hard Labels

Understanding the functional differences between soft and hard targets clarifies why distillation works.

CharacteristicHard Target (One-Hot)Soft Target
InformationSingle bit of truth (class ID).Rich probability distribution.
Gradient SignalProvides a single, strong gradient for the correct class.Provides many smaller, nuanced gradients across all classes.
RegularizationLimited implicit regularization.Strong explicit regularization via dark knowledge.
Noise HandlingTreats all misclassifications equally.Encodes similarity; a mistake between 'cat' and 'dog' is less penalized than between 'cat' and 'airplane'.

Soft targets provide a denser, more informative training signal, which is particularly valuable when the student model has limited capacity, as it learns a smoother, more generalizable function.

06

Applications Beyond Classification

While foundational to classification tasks, the concept of soft targets extends to other domains:

  • Regression: Teacher's continuous predictions (with uncertainty estimates) can serve as soft targets.
  • Reinforcement Learning: In policy distillation, the action probability distribution (policy) of a complex teacher agent is distilled into a student.
  • Object Detection: The teacher's bounding box confidence scores and class distributions for region proposals can be soft targets.
  • Natural Language Processing: Teacher's next-token probability distributions over a large vocabulary are used to distill language models (e.g., DistilBERT).
  • Cross-Modal Tasks: A student model in one modality (e.g., text) can learn from the soft predictions of a teacher in another modality (e.g., vision).

The core principle remains: transferring the teacher's refined, probabilistic understanding of the task is more effective than training only on ground-truth data.

MECHANISM

How Do Soft Targets Work in Distillation?

Soft targets are the probability distributions output by a teacher model, which serve as a richer training signal for a student model than traditional hard labels.

Soft targets, also called soft labels, are the output of a teacher model's final softmax layer, typically after applying temperature scaling (T > 1). This process softens the probability distribution, reducing the confidence gap between the top prediction and other classes. This distribution encodes dark knowledge—the teacher's learned understanding of inter-class similarities—which provides a more informative gradient for the student model than a one-hot encoded hard label.

During training, the student model minimizes a distillation loss, such as Kullback-Leibler (KL) Divergence, between its own softened outputs and the teacher's soft targets. This primary objective is often combined with a standard cross-entropy loss using the original hard labels. By learning to match this richer probability distribution, the student generalizes better, often achieving higher accuracy than if trained on hard labels alone, despite having significantly fewer parameters.

KNOWLEDGE DISTILLATION

Soft Targets vs. Hard Labels: A Comparison

A comparison of the two primary types of supervisory signals used to train machine learning models, highlighting their distinct properties and roles in knowledge distillation.

Feature / CharacteristicSoft Targets (Soft Labels)Hard Labels (One-Hot Labels)

Definition

A probability distribution over classes, typically the output of a teacher model's softmax layer (often with temperature scaling).

A one-hot encoded vector assigning a probability of 1.0 to the ground-truth class and 0.0 to all others.

Information Content

Rich, containing relative probabilities and inter-class similarity information (dark knowledge).

Sparse, containing only the identity of the single correct class.

Primary Use Case

The primary learning signal in knowledge distillation for training a student model.

The standard supervisory signal for training a model directly on a labeled dataset.

Source

Generated by a pre-trained teacher model or an ensemble.

Derived directly from the dataset's ground-truth annotations.

Training Objective

Minimize divergence (e.g., KL Divergence) between student and teacher output distributions.

Minimize cross-entropy loss between model predictions and the one-hot vector.

Effect on Model Calibration

Encourages the student model to produce calibrated, less overconfident probability estimates.

Can lead to overconfident predictions, as the model is trained to output extreme probabilities.

Role in Distillation Loss

Forms the basis of the distillation loss term (e.g., L_KD).

Forms the basis of the standard cross-entropy loss term (e.g., L_CE), often used alongside distillation loss.

Handling of Label Noise / Ambiguity

Robust; provides a probabilistic, softer target for ambiguous or mislabeled examples.

Brittle; incorrect or noisy hard labels directly contradict the model's training objective.

SOFT TARGETS / SOFT LABELS

Practical Applications and Examples

Soft targets are the primary vehicle for transferring 'dark knowledge' from a teacher to a student model. Their applications extend beyond standard classification to improve model calibration, enable data-efficient training, and facilitate learning in complex domains.

01

Core Mechanism in Knowledge Distillation

The canonical use of soft targets is in Knowledge Distillation (KD). A pre-trained teacher model (e.g., a large BERT model) generates softened class probabilities for a training batch. The student model (e.g., DistilBERT) is then trained using a composite loss:

  • Distillation Loss (KL Divergence): Minimizes the statistical difference between the student's and teacher's soft predictions.
  • Hard Label Loss (Cross-Entropy): Ensures alignment with the ground-truth one-hot labels. This dual signal provides richer information than hard labels alone, allowing the student to learn inter-class similarities (e.g., that a 'cat' is more similar to a 'lynx' than to a 'truck').
02

Improving Model Calibration and Generalization

Models trained solely on hard one-hot labels often become overconfident, assigning near-1.0 probability to their predictions even when wrong. Training with soft targets acts as a regularizer:

  • Label Smoothing Effect: Soft targets inherently prevent the model from becoming maximally confident on any single class.
  • Better Uncertainty Estimation: The student learns to output more nuanced probability distributions that better reflect true uncertainty, especially on ambiguous or out-of-distribution samples.
  • Reduced Overfitting: The softened signal provides a less noisy training target, which can improve generalization performance on validation and test sets.
03

Enabling Data-Free and Data-Efficient Training

Soft targets unlock training paradigms where original data is scarce or unavailable:

  • Data-Free Distillation: A teacher model can generate soft labels for synthetically created inputs (e.g., via adversarial generation), enabling a student to be trained without any real data.
  • Dataset Distillation: The goal is to synthesize a tiny, core dataset where the soft labels for each synthetic sample capture the essential information of a large original dataset.
  • Learning from Noisy Labels: In crowdsourced or weakly labeled data, aggregating multiple annotations into a soft label (a probability distribution) can provide a more robust learning signal than using a single, potentially incorrect, hard label.
04

Cross-Modal and Policy Distillation

The concept extends to transferring knowledge between different model types and domains:

  • Cross-Modal Distillation: A powerful image teacher model generates soft labels for a set of images. A text-based student model (e.g., a vision-language model's text encoder) learns to predict these labels from textual descriptions, transferring visual knowledge into the language modality.
  • Policy Distillation in Reinforcement Learning (RL): A complex RL teacher agent's action-selection policy (a probability distribution over actions) serves as the soft target. A simpler, more efficient student policy is trained to mimic this distribution, enabling deployment in latency-sensitive environments.
  • Federated Knowledge Distillation (FKD): A central server sends a teacher model's soft predictions to client devices. Local student models train on this consensus, sharing only soft labels instead of raw private data, enhancing privacy.
05

Temperature Scaling for Information Control

The temperature (T) parameter is a critical hyperparameter for manipulating the information content of soft targets.

  • High Temperature (T >> 1): Dramatically softens the probability distribution, making it more uniform. This emphasizes the dark knowledge—the relative differences between non-true classes—which is most valuable for distillation.
  • Low Temperature (T ≈ 1): Produces a distribution closer to the original hard targets. Used in later training stages or when the student capacity is high.
  • Practical Tuning: A common practice is to use a high T (e.g., 4-20) during the main distillation phase and anneal it to 1 for final fine-tuning. The loss function scales the distillation loss by to keep gradients manageable.
06

Real-World System: DistilBERT and TinyBERT

Prominent examples demonstrate the industrial application of soft targets:

  • DistilBERT: Uses a triple loss during pre-training: 1) Language Modeling loss (MLM), 2) Cosine Embedding loss on hidden states, and 3) Distillation loss on soft labels from BERT-base. This allows it to achieve 97% of BERT's GLUE score with 40% fewer parameters.
  • TinyBERT: Implements a two-stage distillation (general and task-specific) that transfers knowledge from multiple layers:
    • Embedding-layer output
    • Attention matrices (Query, Key, Value)
    • Hidden states of Transformer layers
    • Prediction-layer logits (soft targets) This comprehensive use of soft information at different abstraction levels enables extreme compression without catastrophic performance loss.
SOFT TARGETS / SOFT LABELS

Frequently Asked Questions

Soft targets, also known as soft labels, are the probability distributions output by a teacher model's final softmax layer. They contain richer inter-class similarity information than hard one-hot labels and serve as the primary learning signal for a student model in knowledge distillation.

Soft targets, also called soft labels, are the continuous-valued probability distributions output by a neural network's final softmax layer, typically after applying temperature scaling (T > 1). Unlike hard targets (one-hot encoded ground truth labels), which assign all probability mass to a single class, soft targets distribute probability across all possible classes, capturing the teacher model's relative confidence and the dark knowledge of inter-class similarities. For example, an image of a husky might yield a soft target of [dog: 0.7, wolf: 0.25, cat: 0.05], revealing the model's understanding of visual and semantic relationships that a simple "dog" label does not.

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.