This is the hands-on companion to Softmax for output layers . The parent note built the machine; here we run it on every kind of input it could ever see — big numbers, tiny numbers, negatives, ties, a single class, extreme gaps, a word problem, and an exam twist. Nothing here contradicts the parent; we only go deeper and cover the corners.
Before line one, a promise: you never need to have seen e z , a "distribution," or a "gradient" before. We rebuild each as it appears.
Intuition The three-step machine
Softmax takes a list of raw scores (called logits — just numbers the network spat out, no rules on them) and returns a list of shares of a pie that all add to one whole pie.
Exponentiate: turn each score z into e z . The symbol e z means "the number 2.718 … raised to the power z ." Its one job here: it is always positive and it grows fast , so a bigger score gets a much bigger positive weight.
Add them up: that total is the "size of the whole pie."
Divide: each weight over the total = that class's slice.
Every case softmax can be handed. Each later example is tagged with the cell it covers.
Cell
Input class
What is special
Example
A
All small positive logits
ordinary, no tricks
Ex 1
B
Mixed signs (negative logits)
must not give negative "probabilities"
Ex 2
C
Huge logits (overflow)
needs the max-subtraction shift
Ex 3
D
An exact tie between logits
equal slices — symmetry
Ex 4
E
Extreme gap (one logit dominates)
limiting behaviour → argmax
Ex 5
F
Single class (K = 1 )
degenerate: must output 1
Ex 6
G
Word problem (real-world)
translate a story into logits
Ex 7
H
Exam twist: temperature scaling
dividing by T sharpens/softens
Ex 8
I
Gradient sanity (p − t )
check the learning signal's sign
Ex 9
Recall Why these cells and not others?
Cell E ::: The limiting case: as gaps grow, softmax approaches the hard argmax — proves it is a soft max.
Cell F ::: The degenerate case K = 1 : one class must always get probability 1 ; a formula that failed here would be broken.
Cell D ::: The symmetry case: identical inputs must give identical outputs, or the function is unfair.
Worked example Ex 1 · Cell A
Logits z = [ 2.0 , 1.0 , 0.1 ] . Find p .
Forecast: which class wins, and by how much? Guess before reading.
Exponentiate: e 2.0 = 7.389 , e 1.0 = 2.718 , e 0.1 = 1.105 .
Why this step? Turn scores into positive weights and blow up the gap between them.
Sum: 7.389 + 2.718 + 1.105 = 11.212 .
Why this step? That is the size of the whole pie (the normalizer).
Divide: p 1 = 7.389/11.212 = 0.659 , p 2 = 2.718/11.212 = 0.242 , p 3 = 1.105/11.212 = 0.099 .
Why this step? Slices of the pie — a valid distribution.
Verify: 0.659 + 0.242 + 0.099 = 1.000 ✔ and each is in ( 0 , 1 ) ✔. Class 1 wins with 66% .
Worked example Ex 2 · Cell B
Logits z = [ − 1.0 , 0.0 , 2.0 ] . A naive "divide raw scores by their sum" would give − 1/1 = − 1 — a negative probability , which is nonsense. Watch softmax fix it.
Forecast: does the negative logit get a negative slice, or just a small positive one?
Exponentiate: e − 1.0 = 0.368 , e 0.0 = 1.000 , e 2.0 = 7.389 .
Why this step? e z of a negative number is still positive (it is 1/ e = 0.368 ) — this is exactly why we exponentiate instead of using raw logits.
Sum: 0.368 + 1.000 + 7.389 = 8.757 .
Divide: p = [ 0.042 , 0.114 , 0.844 ] .
Verify: all positive despite the negative input ✔; sum = 0.042 + 0.114 + 0.844 = 1.000 ✔. The negative logit still earns a small positive slice — no class is ever fully starved.
Worked example Ex 3 · Cell C
Logits z = [ 1000 , 1001 , 1002 ] . Computing e 1002 directly overflows to inf. Use the shift.
Forecast: after the fix, will the answer be identical to using the raw numbers, or an approximation?
Subtract the max c = − 1002 : shifted = [ − 2 , − 1 , 0 ] .
Why this step? Softmax is shift-invariant : adding the same constant c to every logit multiplies top and bottom by e c , which cancels. So the answer is identical , only overflow-safe.
Exponentiate: e − 2 = 0.135 , e − 1 = 0.368 , e 0 = 1.000 .
Sum: 0.135 + 0.368 + 1.000 = 1.503 .
Divide: p = [ 0.090 , 0.245 , 0.665 ] .
Verify: sum = 0.090 + 0.245 + 0.665 = 1.000 ✔. The gaps are 1 apart just like Ex-style [ − 2 , − 1 , 0 ] , so the distribution is a legitimate, exact result — no NaN. See Temperature Scaling for a related logit rescaling.
Worked example Ex 4 · Cell D
Logits z = [ 3.0 , 3.0 , 3.0 , 3.0 ] , so K = 4 .
Forecast: four equal scores — what must each slice be?
Exponentiate: all four give e 3 = 20.086 (identical).
Why this step? Equal inputs → equal weights; softmax cannot break a genuine tie.
Sum: 4 × 20.086 = 80.342 .
Divide: each p i = 20.086/80.342 = 0.25 .
Verify: 4 × 0.25 = 1.000 ✔. This is the uniform distribution 1/ K — the highest-entropy answer, exactly what Maximum Entropy Distributions predicts when no class is favoured. Note it does not depend on the value 3.0 ; [ 0 , 0 , 0 , 0 ] gives the same 0.25 each (shift-invariance again).
Worked example Ex 5 · Cell E
Logits z = [ 10 , 0 , 0 ] , then push to [ 100 , 0 , 0 ] . What happens in the limit?
Forecast: as the top logit runs to + ∞ , does the winner's probability hit exactly 1 , or only approach it?
For [ 10 , 0 , 0 ] : e 10 = 22026.5 , e 0 = 1 , e 0 = 1 . Sum = 22028.5 .
Divide: p = [ 0.99991 , 0.0000454 , 0.0000454 ] .
Why this step? The huge weight dominates the pie; the others get crumbs.
Limit reasoning for [ 100 , 0 , 0 ] : e 100 so dwarfs the two 1 s that p → [ 1 , 0 , 0 ] but never exactly — the losers keep an infinitesimal positive slice.
Verify: 0.99991 + 0.0000454 + 0.0000454 = 1.0000 ✔. This is why softmax is a soft argmax: infinite gap ⇒ hard pick [ 1 , 0 , 0 ] , finite gap ⇒ smooth version. See Logits and Log-Odds .
Worked example Ex 6 · Cell F
Only one class exists: z = [ z 1 ] , K = 1 . Try z 1 = − 4.7 (any value).
Forecast: with nothing to compete against, what must p 1 be?
Exponentiate: e − 4.7 = 0.00910 .
Sum: the whole pie is just that one weight: 0.00910 .
Divide: p 1 = 0.00910/0.00910 = 1.0 .
Why this step? Numerator equals denominator — they are the same single term.
Verify: p 1 = 1.0 regardless of z 1 ✔. A one-class softmax is always certain — the degenerate boundary the formula handles correctly.
Worked example Ex 7 · Cell G
A weather model scores tomorrow: sunny gets logit 2.2 , cloudy 2.0 , rainy − 0.5 . Report the forecast probabilities.
Forecast: sunny and cloudy are close — will their probabilities be close too?
Exponentiate: e 2.2 = 9.025 , e 2.0 = 7.389 , e − 0.5 = 0.607 .
Why this step? Convert the model's raw preference scores into positive weights.
Sum: 9.025 + 7.389 + 0.607 = 17.021 .
Divide: p sun = 0.530 , p cloud = 0.434 , p rain = 0.036 .
Verify: 0.530 + 0.434 + 0.036 = 1.000 ✔ (units: probabilities, dimensionless). A small logit gap (0.2 ) gives a small probability gap — sunny barely beats cloudy, exactly the "uncertain call" a human would make. Note: because these are mutually exclusive outcomes we use softmax, not independent Sigmoid Activation (that would be for "could be BOTH sunny and cloudy").
Worked example Ex 8 · Cell H
Same logits as Ex 1, z = [ 2.0 , 1.0 , 0.1 ] , but first divide every logit by a temperature T = 2 before softmax. Compute p and compare.
Forecast: does raising T make the winner more confident or less ?
Scale: z / T = [ 1.0 , 0.5 , 0.05 ] .
Why this step? Dividing shrinks the gaps between logits (see Temperature Scaling ).
Exponentiate: e 1.0 = 2.718 , e 0.5 = 1.649 , e 0.05 = 1.051 .
Sum: 2.718 + 1.649 + 1.051 = 5.418 .
Divide: p = [ 0.502 , 0.304 , 0.194 ] .
Verify: sum = 0.502 + 0.304 + 0.194 = 1.000 ✔. Compare to Ex 1's [ 0.659 , 0.242 , 0.099 ] : with T = 2 the winner dropped from 66% to 50% — higher T softens (more uniform), lower T sharpens. As T → ∞ you recover the uniform Cell-D answer.
Worked example Ex 9 · Cell I
Predictions p = [ 0.7 , 0.2 , 0.1 ] , true class is index 0, so the one-hot target is t = [ 1 , 0 , 0 ] (a 1 on the truth, 0 elsewhere). Find the Cross-Entropy Loss gradient w.r.t. the logits.
Forecast: which entries are negative, which positive, and what does the sign mean ?
Apply the clean rule ∂ z k ∂ L = p k − t k .
Why this step? Softmax + cross-entropy collapse to prediction-minus-target — no messy chain (proven in Backpropagation ).
Subtract: [ 0.7 − 1 , 0.2 − 0 , 0.1 − 0 ] = [ − 0.3 , 0.2 , 0.1 ] .
Verify: the gradient entries sum to − 0.3 + 0.2 + 0.1 = 0 ✔ (always true, since both p and t sum to 1 ). Sign check: negative on the true class means gradient descent will raise its logit; positive on wrong classes lowers theirs — precisely correct learning.
Common mistake Corner-case traps these examples expose
Trap A (from Cell C): "The formula has no subtraction, so my code needn't either." Fix: always subtract max z — mathematically identical (Ex 3), numerically vital.
Trap B (from Cell E): "A confident p = 0.9999 means the model is right." Fix: it only means one logit is far ahead; it can be confidently wrong .
Trap C (from Cell F): "Softmax needs at least two classes." Fix: K = 1 works and must return exactly 1 .
Trap D (from Cell H): "Bigger temperature = more confident." Fix: the reverse — bigger T flattens toward uniform.
In Ex 2, why didn't the negative logit produce a negative probability?
In Ex 3, is the shifted answer exact or approximate?
In Ex 4, why is every slice exactly 1/ K ?
In Ex 5, does the winner ever reach exactly 1 ?
In Ex 8, does T = 2 sharpen or soften the distribution?
What does the exponential guarantee for negative logits? The output is still positive (e − 1 = 0.368 ), so no probability is ever negative.
Is max-subtraction exact or an approximation? Exact — shift-invariance means the ratio is unchanged.
Softmax of K equal logits gives what? The uniform distribution 1/ K on every class.
Does softmax ever output exactly 1 for one class (with K > 1 )? No — only in the limit; losers keep an infinitesimal positive slice.
Higher temperature T does what to the distribution? Softens it toward uniform.