ML0028 Softmax

What is the Softmax activation function, and what is its purpose?

Answer

Softmax is the activation used in the output layer for multi-class classification: it converts a vector of raw scores (logits) into a normalized probability distribution over the classes. Each output is the exponentiated logit divided by the sum of exponentiated logits, so every output lies in (0, 1) and all outputs sum to exactly 1, a genuine probability distribution that can be read as the model’s confidence in each class. Softmax assumes classes are mutually exclusive (one true class per sample); for multi-label problems where an input can belong to several classes at once, per-class sigmoid outputs are used instead, since each class needs an independent probability. Paired with cross-entropy loss, softmax gives the clean gradient p - y, which is why the combination is the standard for multi-class training.

(1) Purpose: Turn arbitrary logits into a probability distribution: outputs in (0,1), summing to 1.
(2) Amplification: Exponentiation sharpens differences: the largest logit dominates the distribution.
(3) Scope: Multi-class (mutually exclusive) problems with cross-entropy loss; multi-label problems use independent sigmoids instead.

Bar chart of raw logits transformed into softmax probabilities summing to one

Figure 1: Softmax in action: raw logits (top) of arbitrary scale and sign are exponentiated and normalized into a probability distribution (bottom) that sums to 1; the relative order is preserved but differences are amplified.

Mathematical Formulation:
\mathrm{Softmax}(z_i) = \frac{e^{z_i}}{\sum_{j=1}^{K} e^{z_j}}
\sum_{i=1}^{K} \mathrm{Softmax}(z_i) = 1
\mathrm{Softmax}(z_i / T) = \frac{e^{z_i / T}}{\sum_{j=1}^{K} e^{z_j / T}} \quad \text{(with temperature } T \text{)}

Where:

  • z_i is the raw score (logit) for class i, and K the number of classes.
  • The exponential makes every term positive; dividing by the total normalizes the vector to sum 1.
  • T is an optional temperature: a value below 1 sharpens the distribution, T > 1 softens it (used in distillation and sampling).
Softmax probability distributions at different temperatures from sharp to nearly uniform

Figure 2: Temperature controls sharpness: low temperature pushes probability mass onto the top class (hard distribution), high temperature flattens toward uniform: the same logits, three very different distributions.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *