Before we start, four objects appear in almost every problem — let us pin them down precisely so nothing here relies on memory.
Now, one shared picture of the whole machine. Every exercise on this page lives in one of these four boxes.
Read it left to right: raw logitszk (any real number) → exp makes them positive → divide by the total makes them a probability pie → compare to the one-hot trutht to get the error p−t. Below, each exercise announces which box it lives in, so keep this figure in view.
To make the "SHARE the pie" box concrete before the numbers start, here is the same logit vector at three temperatures of confidence — watch the tall bars steal probability from the short ones:
Goal: read the formula and plug numbers in. No traps yet, just fluency.(Pipeline box in play: the third box — "share / sum".)
Recall Solution L1.1
The denominator is the total of every exponentiated logit — one shared number for all classes (the size of the whole pie in the third box of figure s01). Because every pk is divided by that same total,
∑kpk=∑jezj∑kezk=1.
The numerator sum and denominator sum are identical, so they cancel to exactly 1. This is why softmax outputs form a valid probability distribution: they always add to the whole pie.
Recall Solution L1.2
Exponentiate: e1=e1=e1, three identical numbers.
Divide each by their sum: each class gets 3e1e1=31.
p=(31,31,31)≈(0.333,0.333,0.333).Meaning: when all scores tie, softmax says "I have no idea" — perfectly uniform. This is the maximum-uncertainty case, matching the flat, equal-height panel of figure s02.
Goal: run the full compute pipeline and one gradient step.(Pipeline boxes in play: all four boxes of figure s01, end to end.)
Recall Solution L2.1
Exponentiate using elna=a (box 2):
e0=1,eln3=3,eln6=6.
Sum =1+3+6=10 (box 3 normalizer).
Divide:
p=(101,103,106)=(0.1,0.3,0.6).
Notice the logs were chosen so the pie splits into clean tenths. Highest logit (ln6) → highest probability (0.6). ✅
Recall Solution L2.2
One-hot zeroes every term except the true class k=3 (only t3=1):
J=−(0⋅log0.1+0⋅log0.3+1⋅log0.6)=−log0.6.J=−ln(0.6)≈0.5108.Meaning: loss depends only on the probability you gave the correct class. Give it 0.6 → pay 0.51. Had the model given class 3 a probability near 1, the loss would fall toward 0.
Recall Solution L2.3
For m=3: p3−t3=0.6−1=−0.4.
∇w3J=(−0.4)(2,−1)=(−0.8,0.4).
The gradient is negative-scaled because the true class was under-predicted (p3<1). Gradient descent subtracts this, so w3 moves in the +(0.8,−0.4) direction — raising z3 next time. The model learns to trust class 3 more for this input. ✅
Goal: reason about structure — invariances, limits, why the gradient is clean.(Pipeline boxes in play: box 2 "exp" for invariance; boxes 3→4 for the gradient.)
Recall Solution L3.1
Start from the definition with shifted logits zk+c:
∑jezj+cezk+c=∑jezjecezkec=ec∑jezjecezk.
The factor ec appears in every numerator and in the denominator, so it factors out and cancels:
=∑jezjezk=softmax(zk).■This is the whole justification for the log-sum-exp trick: choose c=−maxkzk so the largest exponent becomes 0 (and e0=1, never overflowing) — the probabilities are provably identical.
Recall Solution L3.2
Divide numerator and denominator by ez1 (legal since ez1=0):
p1=ez1/ez1+ez2/ez1ez1/ez1=1+ez2−z11=1+e−(z1−z2)1=σ(z1−z2).■Meaning: with two classes only the differencez1−z2 matters — one extra degree of freedom (the common part) is invisible. That is exactly the shift-invariance of L3.1 showing up as Logistic Regression's single logit.
Recall Solution L3.3
Part (a) — deriving the softmax Jacobian. Write pk=Sezk with normalizer S=∑jezj. We differentiate with respect to one logit zm using the quotient rule; note ∂zm∂S=ezm (only the j=m term of S depends on zm), and ∂zm∂ezk=ezkδkm (the top moves only when k=m — this is exactly what δkm encodes).
∂zm∂pk=S2(∂zmezk)S−ezk(∂zmS)=S2ezkδkmS−ezkezm.
Split into two fractions and recognize Sezk=pk and Sezm=pm:
=Sezkδkm−Sezk⋅Sezm=pkδkm−pkpm=pk(δkm−pm).✓Intuition: raising zm grows its own probability (the δkm "self" term, present only when k=m) but simultaneously steals from every class by inflating the shared normalizer S (the −pkpm "competition" term). Softmax outputs are coupled — one bar rising pushes the others down (exactly what figure s02 shows).
Part (b) — the cancellation. Differentiate J; the chain rule on logpk gives pk1∂zm∂pk:
∂zm∂J=−∑ktkpk1∂zm∂pk=−∑ktkpk1pk(δkm−pm).
The pk1cancels the pk — the beautiful cancellation:
=−∑ktk(δkm−pm)=−∑ktkδkm+pm∑ktk.
Now ∑ktkδkm=tm (the delta picks out only the k=m term) and ∑ktk=1 (one-hot):
=−tm+pm⋅1=pm−tm.■
Every messy exp/normalization term vanished, leaving prediction minus truth.
Part (c) — chain rule from logit to weights. The loss depends on wmonly through the logit zm=wm⊤x. So by the chain rule, the derivative with respect to one weight component wm,i is
∂wm,i∂J=∂zm∂J⋅∂wm,i∂zm.
The first factor is pm−tm from Part (b). For the second, since zm=∑iwm,ixi, differentiating w.r.t. one weight wm,i leaves only its own input: ∂wm,i∂zm=xi. Therefore
∂wm,i∂J=(pm−tm)xi.
Stacking over all components i into a vector is exactly
∇wmJ=(pm−tm)x.■
This is the rule we simply used in L2.3 — now derived: the scalar error (pm−tm) scales the input direction x.
Goal: combine numerical stability, loss, and gradient into one coherent computation.(Pipeline boxes in play: all four boxes of figure s01, with box 2 made numerically safe.)
Recall Solution L4.1
maxkzk=12. Subtract it from each (shift-invariance guarantees the answer is unchanged):
z′=(0,−2,−1).
Exponentiate the safe, small numbers:
e0=1,e−2=0.13534,e−1=0.36788.
Sum =1+0.13534+0.36788=1.50322.
Divide:
p=(1.503221,1.503220.13534,1.503220.36788)≈(0.6652,0.0900,0.2447).
Without the trick you would have computed e12≈162754 — fine here, but the pattern is identical, and for logits like 1000 it prevents inf. Highest logit → highest prob. ✅
Recall Solution L4.2
(a) One-hot picks class 2: J=−logp2=−ln(0.0900)≈2.4079. High loss — the model badly under-rated the true class (0.09).
(b) Error for m=2: p2−t2=0.0900−1=−0.9100.
∇w2J=(−0.9100)(1,0)=(−0.9100,0).
Large negative error → a big corrective step: descent subtracts this, pushing w2 up strongly to raise z2. The second component is 0 because x2=0 carries no information to update. ✅
Goal: prove a property and connect the whole family.
Recall Solution L5.1
Compute the new logits after subtracting a from every weight vector:
zk′=(wk−a)⊤x=wk⊤x−a⊤x=zk−c,
where c=a⊤x is the same scalar for every class (it depends on a and x, not on k). So all logits drop by the identical amount c.
By shift-invariance (Exercise L3.1), subtracting a common constant c from all logits leaves softmax unchanged:
softmax(zk′)=softmax(zk−c)=softmax(zk).Conclusion: the model is over-parameterized — an entire direction of weight-space (subtract any a) produces zero change in predictions. You can therefore pin wK=0 without losing any expressive power, giving effectively K−1 independent weight vectors. This matches Logistic Regression (K=2), which needs just one logit/weight vector, not two. ✅
Recall Solution L5.2
(a) Softmax:e3=20.0855, e1=2.71828, sum =22.8038.
p1=22.803820.0855≈0.8808.(b) Sigmoid of difference:z1−z2=3−1=2.
σ(2)=1+e−21=1+0.135341=1.135341≈0.8808.
They agree to four decimals. ✅ This is the Neural Network Output Layer fact: a 2-way softmax head is a sigmoid unit on the logit gap — the Logistic Regression special case, using Cross-Entropy Loss as its objective, itself derived by Maximum Likelihood Estimation.