What is softmax?
Softmax turns a neural network's raw scores (logits) into a probability distribution whose values lie between 0 and 1 and sum to 1. Each score is exponentiated and divided by the sum of all exponentials, so larger scores get larger probabilities.
Unlike the sigmoid, which turns one score into an independent probability, softmax normalises several classes' scores together, so one class gaining probability means others lose it. A 1989 study replaced the usual logistic output non-linearities with this normalised exponential.
- Topic
- Machine learning, models and training
- Also known as
- Normalised exponential, softargmax
- Origin
- 1989, probabilistic interpretation of neural network outputs at NIPS
How softmax works
- The model produces a raw score (logit) per class or token.
- Scores can be divided by a temperature, normally 1.
- Scores are exponentiated and divided by their sum.
- In training it is paired with a cross-entropy loss, making the derivative before the output the predicted probability minus a one-hot target.
In more detail
Softening the distribution with temperature
Logits can be divided by a temperature value before softmax. The temperature is normally 1; a higher value produces a softer distribution spread more evenly across classes. In knowledge distillation these soft targets from a large model are passed to a small one.
Commonly confused terms
| Term | How it differs |
|---|---|
| Logit | A logit is the unbounded raw score fed into softmax. Softmax is the function that turns these scores into probabilities summing to 1; the order of scores is kept but the scale becomes probability. |
Why softmax matters for on-premises AI
Softmax produces class probabilities in classification networks and next-token probabilities in language models. In the 2017 study introducing the Transformer, attention weights also come from softmax over query and key dot products, which are scaled because at large dimensions they push softmax into regions with extremely small gradients. A knowledge distillation study raises the temperature for softer distributions and trains a small model on them.
An insurer's document classification model gives softmax probabilities for policy, claim notice, invoice and other classes. Documents whose top probability falls below a threshold go to human review; the team tunes the threshold to the validation set's error rate.
Common questions
When is softmax preferred over sigmoid?
Softmax is used when classes are mutually exclusive, meaning each example belongs to one class. When an example can carry several labels at once, a separate sigmoid is used for each label.
Does softmax output show model confidence accurately?
Not always. Softmax gives a distribution summing to 1, but these probabilities may not match the model's actual accuracy. Decision thresholds are therefore tuned on validation data, with model calibration applied where needed.
Related terms
Sources
- Training Stochastic Model Recognition Algorithms as Networks can Lead to Maximum Mutual Information Estimation of Parameters, NIPS, 1989
- Distilling the Knowledge in a Neural Network, NIPS Deep Learning Workshop, 2014
- Attention Is All You Need, arXiv, 2017
In the glossary: Glossary, R to Z