2.2.12 · D3Linear & Logistic Regression

Worked examples — Multinomial - softmax regression

3,479 words16 min readBack to topic

This page is a case gym. The parent softmax note built the machinery; here we throw every kind of input at it — negatives, ties, zeros, huge numbers, a word problem, an exam twist — and grind each one by hand. If you can do all of these, nothing about softmax can surprise you.

Before we start, a one-line refresher of the only two operations you need, in plain words:

Every example below is just: EXP, add up, SHARE. Watch how each weird input still obeys these two moves.


The scenario matrix

Softmax + its cross-entropy loss can be hit with a small, finite family of situations. Here is the full grid, and which worked example nails each cell. One example per cell, no gaps.

Cell Situation Why it's tricky Example
A All logits positive, distinct baseline warm-up Ex 1
B Mix of negative and positive logits of a negative number Ex 2
C All logits equal (degenerate tie) must give uniform Ex 3
D Huge logits (overflow risk) on a computer Ex 4
E Limiting case: one logit softmax one-hot (arg-max) Ex 5
F collapse to sigmoid shows softmax ⊇ sigmoid Ex 6
G Loss + gradient for a correct-ish prediction sign check Ex 7
H Loss + gradient for a badly wrong prediction large loss, large push Ex 8
I Real-world word problem (3-class classifier) reading logits from a story Ex 9
J Exam twist: shift-invariance + stability proof by numbers conceptual trap Ex 10
K Very negative logits (underflow risk) on a computer Ex 11
Figure — Multinomial - softmax regression

How to read the map above. Each colored dot is one cell of the table — its bold letter (A–K) is the cell label, the word underneath is the situation in shorthand, and the italic label below that (Ex1…Ex11) is the worked example that solves it. The gray dashed line is the "study path": it visits the dots in order A→B→C→…→K, so if you follow the dashes you have covered every scenario softmax can present exactly once. Nothing is plotted numerically here — it is a legend/index, a picture of the checklist, not a graph of data.


Ex 1 — Cell A: all-positive, distinct logits


Ex 2 — Cell B: negative logits mixed in


Ex 3 — Cell C: the degenerate tie (all logits equal)


Ex 4 — Cell D: huge logits (overflow) and the fix


Ex 5 — Cell E: limiting case, one logit runs to

Figure — Multinomial - softmax regression

The figure shows climbing toward as increases — the "temperature" of the decision cooling into certainty.


Ex 6 — Cell F: collapses to the sigmoid


Ex 7 — Cell G: loss + gradient, prediction mostly right


Ex 8 — Cell H: loss + gradient, prediction badly wrong


Ex 9 — Cell I: real-world word problem


Ex 10 — Cell J: exam twist (shift-invariance + why we subtract the max)


Ex 11 — Cell K: very negative logits (underflow) and the same fix


Active Recall

Recall (Ex 1 monotonicity) Why does a bigger logit always get a bigger probability?

Because is increasing, so , and dividing both by the same total preserves the order.

Recall (Cell B) A logit is

. Is its softmax probability negative? No. . Softmax outputs are always in ; negative logits give small probabilities, never negative ones.

Recall (Cell C) All

logits are equal. What is each probability? Exactly — the uniform distribution. The equal exponentials cancel, leaving only the count.

Recall (Cell E) One logit

, the rest fixed. What does softmax approach? A one-hot vector (all mass on that class). Softmax is the smooth version of arg-max.

Recall (Cell D & K) Subtracting

fixes which two numerical failures? Overflow (a huge logit sends ) and underflow (all logits hugely negative send every so ). The shift forces the top exponent to be , curing both.

Recall (Cell G/H) Why do the entries of

always sum to zero, and does one example update all weight vectors? They sum to zero because and . Yes — all weight vectors update on each example, since is nonzero for every class (they share the normalizer ).

Recall (Cell J) Two logit vectors differ by a constant in every slot. Same softmax?

Yes — shift-invariance. The common factor cancels in the ratio. This is exactly why subtracting the max is loss-free.

Connections