Lensa ML
Lensa ML

How Softmax Works

Step 1 of 6

Raw Logits

Before softmax

z₁2.0
z₂1.0
z₃-1.0
02.0z₁1.0z₂-1.0z₃value

z₁

2.0

z₂

1.0

z₃

-1.0

z₁ is the largest logit — the model favors class 1, but raw values aren't probabilities yet.

Step 1 of 6: Raw Logits

Before softmax

z₁2.0
z₂1.0
z₃-1.0
02.0z₁1.0z₂-1.0z₃value

z₁

2.0

z₂

1.0

z₃

-1.0

z₁ is the largest logit — the model favors class 1, but raw values aren't probabilities yet.

Step 2 of 6: The Softmax Function

eᶻ / Σeᶻ

z₁2.0
z₂1.0
z₃-1.0
Raw Logits2.0z₁1.0z₂-1.0z₃eᶻ / ΣeᶻProbabilities70.5%P₁25.9%P₂3.5%P₃

exp(z₁)

1.000

+

exp(z₂)

0.368

+

exp(z₃)

0.050

=

Σeᶻ

1.418

Probabilities are spread out. Softmax always sums to 1.0, giving a valid probability distribution over classes.

Step 3 of 6: Temperature

Sharpening & smoothing

z₁2.0
z₂1.0
z₃-0.5
Temperature (T)1.00
Raw Logits2.0z₁1.0z₂-0.5z₃eᶻᐟᵀ / ΣeᶻᐟᵀProbabilities69.0%P₁25.4%P₂5.7%P₃T=1.00 — standard

Temperature

1.00

max P

69.0%

Entropy

1.106

T=1 is standard softmax — no temperature scaling applied.

Step 4 of 6: Numerical Stability

The max trick

z₁100
The Max Trick— subtract max(z) before exp to prevent overflow
zᵢzᵢ−max(z)exp(zᵢ−max(z))P
z₁1000.01.00070.5%
z₂99-1.00.36825.9%
z₃97-3.00.0503.5%
Naive exp(zᵢ)70.5%P₁25.9%P₂3.5%P₃max trickStable exp(zᵢ−max(z))70.5%P₁25.9%P₂3.5%P₃

max(z)

100

Naive exp(z₁)

2.7e+43

Stable exp(z₁−max(z))

1.000

exp(100) = 2.7e+43 — already huge. The max trick shifts all logits so the largest is 0, keeping exp values in a safe range. The result is mathematically the same.

Step 5 of 6: Softmax vs Sigmoid

Multi-class vs binary

Sigmoid (binary)
σ(z) = 1 / (1 + e⁻ᶻ)
Softmax (multi-class)
P(i) = eᶻⁱ / Σeᶻʲ
z1.5
0.51.081.8%Yes18.2%NoSigmoid: P(Yes) vs P(No) = 1 − σ(z)σ(z)0.51.076.6%C₁17.1%C₂6.3%C₃Softmax: probability split across 3 classesP(C₁)P(C₂)P(C₃)

SIGMOID σ(z)

0.8176

SOFTMAX P(C₁)

0.7662

Σ SOFTMAX

1.0000

Sigmoid gives a single P(Yes). Softmax splits the same confidence across 3 classes — P(C₁) is lower than σ(z) because probability must be shared.

Step 6 of 6: Softmax in Practice

Classification pipeline

feat₁0.80
feat₂-0.30
feat₃0.50
f10.8f2-0.3f30.5z11.26z2-1.19z30.80softmaxeᶻ/Σeᶻ58.2%Cat5.0%Dog36.8%Bird

logit Cat

1.26

logit Dog

-1.19

logit Bird

0.80

predicted

Cat

The model leans toward Cat, but isn't fully confident. Try moving the feature sliders to see how logits and probabilities change.