2.2.12 · D1Linear & Logistic Regression

Foundations — Multinomial - softmax regression

3,428 words16 min readBack to topic

Before you can read the parent note, you need to see every symbol it throws at you. This page builds each one from nothing — plain words, then a picture, then why the topic can't live without it. Read top to bottom: each idea rests on the one above it.

This is the foundations page for Multinomial / Softmax Regression.


1. The input vector and its dimension

The picture. Think of : then is a single dot on a flat sheet of paper, at horizontal position and vertical position . For it's a dot in a room. For bigger we can't draw it, but it's still "one point in a -dimensional space."

Why the topic needs it. Everything downstream — the scores, the probabilities — is a function of this one point. No input, nothing to classify.

Figure — Multinomial - softmax regression

2. The class label and the count

The picture. Imagine labelled bins standing in a row: bin 1, bin 2, bin 3. Every example belongs in exactly one bin. is the bin's number.

Why the topic needs it. Softmax's whole job is to guess which of the bins the point belongs to, and to grade itself against the true .


3. Weight vectors — one ruler per class

The picture. is an arrow starting at the origin, pointing in the direction that class considers "very much like me." A point lying far along that arrow's direction scores high for class .

Why the topic needs it. These arrows are the only thing the model learns. Training = adjusting the arrows so each points toward its class's examples.


4. The dot product — measuring alignment

The picture. Lay both arrows down. The dot product measures how much of "shadows onto" the direction of (its projection), scaled by how long is. Same direction → large positive shadow. Right angle → zero. Opposite → negative.

Figure — Multinomial - softmax regression

5. The logit — a raw, unbounded score

The picture. Picture contestants, each holding up a scorecard with a number on it. Some numbers are negative (like ), some big (like ). These are the . They're not yet fair, comparable slices of a pie — just raw enthusiasm.

Why the topic needs it. The logits are the bridge: the learned arrows produce them, and softmax will convert them into honest probabilities. The word "logit" will appear everywhere in the parent note.


6. Euler's number and the exponential

The picture. A curve that hugs the floor on the left (near but positive), passes through height at , and rockets upward on the right.

Figure — Multinomial - softmax regression

7. Summation — adding a list up

The picture. A conveyor belt: it visits each item once, dropping it into a running total. The is the belt's counter; it's a dummy — you could rename it and nothing changes.

Why the topic needs it. The softmax denominator is "the total size of all boosted scores" — the whole pie we're about to divide.


8. Probability and normalization — sharing the pie

The picture. A pie chart. Each contestant's boosted score claims a wedge; dividing by the total is just measuring each wedge as a fraction of the full circle. All wedges together = one whole pie = .

Figure — Multinomial - softmax regression

9. Numerical safety — subtracting before exponentiating

Why it works. Adding the same constant to every logit multiplies every by , which cancels in the ratio — softmax is shift-invariant. Choosing pins the largest term at . The parent note calls this the Log-Sum-Exp Trick.


10. The one-hot vector

The picture. light switches, all OFF except the one for the true class, which is ON.

Why the topic needs it. It lets the loss (next section) automatically "pick out" only the true class — every wrong-class term is multiplied by and vanishes.


11. The natural logarithm

The picture. A mirror image of the exponential curve flipped across the diagonal line . On the interval we care about, : the curve sits at or below zero. It equals exactly when , and dives down toward as approaches .

Figure — Multinomial - softmax regression

12. The one-hot vector and cross-entropy loss — grading the guess

The one-hot shortcut. Because is zero everywhere except the true slot, the whole sum collapses to a single term: Why? Every wrong-class term is . So cross-entropy is literally "the negative log of the slice the true class received." Full treatment: Cross-Entropy Loss, derived from Maximum Likelihood Estimation.


13. The partial derivative and the gradient

The picture. Imagine as a hilly landscape whose height depends on all the logits. is the steepness you'd feel if you walked one step purely along the axis, freezing all others. Downhill in that direction lowers the loss.

Figure — Multinomial - softmax regression

Building the gradient, one step at a time. We want where .

Step A — slope of softmax itself. WHAT: first find how each probability moves when we wiggle logit . WHY: the loss is built from the , so by the chain rule we must know their slopes first. Result (a standard exercise you can accept for now): Read it: if the term makes it (raising a logit raises its own probability); if it is (raising one logit steals probability from the others). That sign pattern is exactly the "pie must still sum to 1" behaviour.

Step B — slope of . WHAT: the loss uses , not . WHY: we need the derivative of the log so we can chain it onto Step A. The derivative of is , so WHAT IT LOOKS LIKE: the and the cancel — the messy division disappears. This cancellation is the whole reason softmax and log are paired.

Step C — assemble the loss slope. WHAT: put Step B into . WHY: that is the quantity we actually want to descend. WHY each collapse: because keeps only the term; and because a one-hot vector has exactly one . What remains is astonishingly clean:

Step D — from logits to weights. WHAT: we ultimately steer the weights , not the logits. WHY: since , wiggling changes at a rate of , so we multiply:

The picture in words: "predicted minus true, times input." If the true class's slice is too small, is negative there, and the update pushes to raise that class's logit next time.


14. The prerequisite map

input x in R^d

dot product w_k dot x

weight vector w_k per class

logit z_k raw score

exponential e to the z

softmax p_k probability

summation sigma total

subtract max z for safety

cross-entropy loss minus log p true

natural log

one-hot label t

gradient p minus t times x

partial derivative slope

kronecker delta

class count K and label y

Read it as flow: the input and per-class weights make logits; exp plus the sum (made safe by subtracting the max) make probabilities; probabilities plus the natural log and the one-hot truth make the loss; and the loss's partial derivative — helped by the Kronecker delta — is the clean that training uses.


Equipment checklist

Test yourself — hide the right side and answer aloud.

What does mean in plain words?
One example, described by a list of real-number features; a single point in -dimensional space.
What is ?
The number of classes / categories we sort examples into.
Feature slot vs. example index — how are they written?
Subscript = feature slot; superscript-in-parens = which example.
What does compute, and why that operation?
The dot product — one number measuring how aligned the example is with class 's weight arrow (its projection); it's the natural "direction agreement" score.
What is a logit ?
A raw, possibly-negative, unbounded score for class ; not yet a probability.
Why exponentiate the logits?
is always positive, always increasing, never zero, and smooth — exactly the properties needed to make valid, learnable probabilities.
Is positive or negative?
Positive (); the minus is in the exponent, not the result.
What does represent?
The total of all boosted scores — the whole pie we divide by.
Why divide each by that sum?
To normalize so the probabilities add up to exactly 1.
Why subtract before exponentiating?
Shift-invariance makes the probabilities identical, but it caps the largest exponent at so nothing overflows to infinity.
What does read as?
The probability that the class is , given the input .
What is in ML, its domain, and its sign on ?
The natural log (inverse of ); domain is positive numbers only; on it lies in , equal to exactly at .
What is the one-hot vector ?
A length- list, all zeros except a single 1 at the true class's slot.
Write the cross-entropy loss and its one-hot shortcut.
.
What does the symbol mean?
The partial derivative: how fast changes when only is nudged, holding all other logits fixed — the slope of in the direction.
Why does simplify to ?
The from the log's derivative cancels the inside .
What is the softmax + cross-entropy gradient wrt logit ?
("predicted minus true").
What is ?
1 when , else 0 — the Kronecker delta, used in the softmax derivative.