Exercises — Softmax for output layers
Before we begin, a one-line refresher of the only machine we use, so no symbol is unearned:
We also reuse two companions from the parent:
- The cross-entropy loss for a one-hot target (a vector that is on the true class, elsewhere): . See Cross-Entropy Loss.
- Its clean gradient w.r.t. logits: .
Let's climb.
Level 1 — Recognition
Exercise 1.1
Which of these vectors could be the output of a softmax (over 3 classes)? (a) (b) (c) (d)
Recall Solution
A softmax output must obey two laws: every entry lies in , and the entries sum to exactly 1.
- (a) sums to , all positive → valid. ✔
- (b) contains → impossible, can never give a negative → invalid. ✘
- (c) sums to → invalid (it forgot to normalize). ✘
- (d) sums to , but two entries are exactly and one is exactly . Softmax outputs are strictly in — it can approach but never reach or (that would need an infinite logit gap). So this is a limiting case, not a true softmax output. ✘
Answer: only (a).
Exercise 1.2
The softmax of is what vector, without computing any exponentials?
Recall Solution
All logits are equal, so all are equal, so all shares are equal. With equal shares summing to , each is . Answer: . Equal scores → uniform distribution, regardless of the common value.
Level 2 — Application
Exercise 2.1
Compute softmax of exactly (as fractions).
Recall Solution
The clever part: , so exponentiating undoes the log.
- Tops: , , .
- Sum (normalizer): .
- Divide: .
Answer: . The logits were literally chosen as logs of the desired ratio .
Exercise 2.2
Take logits . First compute their softmax from scratch on this page. Then add to every logit, giving , and find the new softmax.
Recall Solution
Compute the base softmax first — no numbers borrowed.
- Exponentiate: , , .
- Sum (normalizer): .
- Divide: .
Now the shift. Shift-invariance: adding the same constant to every logit multiplies every top by , top and bottom, so it cancels: Answer: the shifted softmax is unchanged, . Softmax only cares about differences between logits, never their absolute level.
Exercise 2.3
For binary logits , show softmax of class 1 equals the sigmoid of the gap , where the sigmoid is .
Recall Solution
Start from softmax and divide top and bottom by to "measure everything relative to class 1": Answer: . This is why 2-class softmax and the Sigmoid Activation are the same machine — the sigmoid is just softmax that has already been reduced to a single logit gap. See also Logits and Log-Odds.
Level 3 — Analysis
Before the next exercise we must earn one new symbol, the Kronecker delta .
Exercise 3.1
Verify the derivative identity for the diagonal case , working from with .
Recall Solution
is a ratio, so we use the quotient rule . We differentiate w.r.t. (the diagonal, ):
- Top , so .
- Bottom . Since contains the term , .
Plug in: On the diagonal , so , and this is exactly . ✔ (Off-diagonal : only the bottom depends on , giving . Here , so matches.)
Exercise 3.2
A network predicts and the true class is index 1 (0-based), so . Compute the loss gradient for each , and say which logit gets pushed up.
Recall Solution
The magic collapse: (prediction minus target).
- :
- :
- :
Gradient descent moves each logit opposite to its gradient. A negative gradient means the logit is pushed up. Only (the true class) has a negative gradient, so logit 1 is pushed up; the two wrong logits are pushed down. Exactly what learning should do — see Backpropagation. Answer: ; logit 1 (true class) goes up.
Exercise 3.3
Show the sum of all cross-entropy gradients over is zero: . Why does this make sense geometrically?
Recall Solution
because probabilities sum to and a one-hot target also sums to . Meaning: the gradient can never shift all logits in the same direction — that would be the shift from Ex 2.2, which changes nothing. So training only ever adjusts the relative pushes: every unit pushed up somewhere is exactly balanced by pushes down elsewhere.
Level 4 — Synthesis
Exercise 4.1 — Temperature
Define tempered softmax for temperature . For , compute the winning probability at and at , and state the limits as and .
Recall Solution
Dividing logits by shrinks (large ) or stretches (small ) the gaps.
- : tops ; sum ; .
- : logits become ; tops ; sum ; .
Bigger softens (0.665 → 0.506, closer to uniform ).
- : all gaps , so (uniform).
- : gaps blow up, the largest logit dominates completely, so (hard argmax).
Answers: , ; limits uniform () and one-hot argmax (). This is Temperature Scaling.
The figure below traces this: the horizontal axis is temperature , the vertical axis is softmax probability. Three curves — burnt-orange for class 1 (), teal for class 2 (), plum for class 3 (). Read it right-to-left: as grows the three curves squeeze toward the dashed uniform line at (all classes tie); as shrinks toward the orange curve rockets to while the others fall to (argmax). The two grey verticals mark the and answers you just computed.

Exercise 4.2 — Maximum entropy
Softmax is the distribution of maximum entropy given fixed expected logit. Without heavy calculus, argue why the uniform distribution (Ex 1.2's case) is the special softmax that maximizes entropy outright.
Recall Solution
Entropy measures "spread-outness / uncertainty." It is largest when no outcome is favored — i.e. all equal. When the logits are all equal, softmax returns exactly the uniform , whose entropy is the maximum possible value . Any unequal logits create a preference, lowering entropy. So softmax with equal logits = the maximum-entropy point, the "least-biased guess." For the full derivation see Maximum Entropy Distributions. Check for : .
Level 5 — Mastery
Exercise 5.1 — The double-softmax destruction
You accidentally apply softmax twice: . Starting from , compute and compare to the correct single softmax . What went wrong?
Recall Solution
- First softmax: (Ex 4.1, ).
- Second softmax treats these tiny numbers as new logits. Their gaps are now minuscule ( instead of ), so exponentiating barely separates them: tops ; sum ; .
Answer: — much flatter than . Applying softmax again shrinks the gaps and pushes everything toward uniform, destroying information. Rule: apply softmax exactly once, to raw logits.
Exercise 5.2 — Overflow-safe computation
Compute softmax of by hand, safely.
Recall Solution
Naïve overflows to inf. Use shift-invariance (Ex 2.2): subtract .
- Shifted: .
- Tops: ; sum .
- Divide: .
Answer: , computed with all exponents — no overflow, and identical to the un-shifted result.
Exercise 5.3 — Degenerate / limiting input
What does softmax return for (all equal, any ), and what happens to as with the other logits held fixed? Cover both edges.
Recall Solution
Equal case: every top equals , so the answer is uniform — independent of (this combines Ex 1.2 and shift-invariance). Runaway case (): dominates the sum, so Answer: uniform for equal logits; approaches one-hot as one logit runs to . Note never exactly equals 1 for finite logits — it only limits there, confirming outputs live in the open interval (why Ex 1.1(d) failed).
The figure below makes the runaway case visible. It fixes and slides up through the values ; each cluster of three bars is one softmax. The horizontal axis groups the three classes, the vertical axis is probability. Watch the class-1 bar climb toward the dashed line at while the class-2 and class-3 bars collapse toward — exactly the , limit. The annotation flags that the bar approaches but never reaches , reconfirming why Ex 1.1(d)'s exact is not a true softmax output.

Active Recall
Level up recognized
Softmax of all-equal logits
Safe-compute trick
Loss gradient w.r.t. logit
Kronecker delta meaning
Connections
- Cross-Entropy Loss — supplies the that yields the clean gradient (Ex 3.2, 3.3).
- Sigmoid Activation — the 2-class reduction of softmax (Ex 2.3).
- Logits and Log-Odds — the raw inputs; gaps are log-odds.
- Maximum Entropy Distributions — justifies the exponential form (Ex 4.2).
- Backpropagation — where the gradient flows.
- Temperature Scaling — the knob of Ex 4.1 / 5-limits.