Chapter 11

Softmax (Turn into Probabilities)

A function that turns a vector into a probability distribution (values in [0,1], sum 1).

Deep learning diagram by chapter

As you complete each chapter, the diagram below fills in. This is the structure so far.

SoftmaxScore → probability(example: e ≈ 3)
Score
3
1
0
Mid
27
3
1
3 to the power
3³=27
3¹=3
3=1
Probability
27/31
3/31
1/31
Divide by sum
27÷31=27/31
3÷31=3/31
1÷31=1/31

3raised to 27(3^3)

27/31=27 ÷ 31

Softmax in deep learning

Softmax is a function that converts multiple scores (numbers) into probabilities. All values become between 0 and 1, and they sum to exactly 1. So you can read them as probabilities.

The formula is softmax(xi)=exijexj\mathrm{softmax}(x_i) = \frac{e^{x_i}}{\sum_{j} e^{x_j}}. Because it uses powers of e (≈2.718), the largest score gets amplified significantly while others shrink relatively. The gap between 1st and 2nd place becomes more pronounced.

Example: scores [3, 1, 0] → e³≈27, e¹≈2.7, e⁰=1 → sum ≈ 23.7 → probabilities → [0.84, 0.11, 0.04]. The score of 3 was only 3× larger than 1, but the probability is about 8× larger!

Softmax is used at the final layer of almost every classification model. 'This photo is 70% dog, 25% cat, 5% bird' lets you see per-class probabilities and how confident the model is.

When combined with cross-entropy loss during training, the gradients work out cleanly and stably. The model naturally learns to 'increase the correct class probability and decrease the rest.'

Softmax's property of 'all positive values that sum to 1' exactly matches the definition of a probability distribution. This makes it the most natural way to convert scores to probabilities, both statistically and theoretically.

Image classification: The model's final layer outputs scores (logits) like [5.2, 2.1, 0.8, ...]. Softmax converts them to [0.70, 0.25, 0.05, ...]—probabilities for each class. The highest probability class is the final answer.

Chatbots & translators: When ChatGPT picks the next word, it scores every word in its vocabulary (tens of thousands!), converts to probabilities via softmax, and samples a word based on those probabilities. High-probability words appear often, but occasionally low-probability words are picked for variety.

Attention mechanism: In translators, relevance scores for 'which input words to focus on' are passed through softmax to become probabilities (weights). These weights create a weighted average of inputs that emphasizes the most relevant parts.

Computation order: ① Compute Z=WX+bZ = W \cdot X + b (logits) ② Compute eZe^Z (problem uses e3e \approx 3) ③ Compute Σ\Sigma (sum) = add all eZe^Z values ④ Y=eZΣY = \frac{e^Z}{\Sigma} (divide each by the sum). Follow this order.

Finding blanks: If Y is blank, compute 'that eZ÷Σe^Z \div \Sigma.' If eZe^Z is blank, compute 'Y×ΣY \times \Sigma.' If Z is blank, reverse from eZe^Z. If Σ\Sigma is blank, just add all eZe^Z values.

Verification: After computing, check that all Y values are between 0 and 1 and sum to 1. If not, there's a calculation error. Also confirm whether the problem uses e3e \approx 3 or e2.718e \approx 2.718.

Softmax turns numbers into values between 0 and 1 that sum to 1. Compute Z=WX+bZ = W \cdot X + b, then eZe^Z, then divide each by the sum (Σ\Sigma) to get probabilities.

Score (ZZ) → 3Z3^Z → divide by sum → probability (YY)

XX
1
1
\cdot
W
1
1
0
1
+
b
1
1
=
ZZ
3
2
3Z3^Z
27
9
Σ\Sigma
36
YY
3/4
1/4

Often used in the final layer for multi-class classification.

Example: step-by-step calculation

Z1=11+11+1=3Z_1 = 1 \cdot 1 + 1 \cdot 1 + 1 = 3
Z2=01+11+1=2Z_2 = 0 \cdot 1 + 1 \cdot 1 + 1 = 2
3Z1=33=273^{Z_1} = 3^3 = 27
3Z2=32=93^{Z_2} = 3^2 = 9
Σ=27+9=36\Sigma = 27 + 9 = 36
Y1=3Z1Σ=2736=34Y_1 = \frac{3^{Z_1}}{\Sigma} = \frac{27}{36} = \frac{3}{4}
Y2=3Z2Σ=936=14Y_2 = \frac{3^{Z_2}}{\Sigma} = \frac{9}{36} = \frac{1}{4}

Problem

Compute Z=WX+bZ = W \cdot X + b, eZ    (e3)e^Z \;\; (e \approx 3), Y=eZΣY = \frac{e^Z}{\Sigma} , then fill in the blank (?).

In this problem we use e = 3 for easy calculation. So eZ=3Ze^Z = 3^Z. (e.g. Z=1 → 3, Z=2 → 9)

Score (ZZ) → 3Z3^Z → divide by sum (Σ\Sigma) → probability (YY)

X
1
1
·
W
1
1
1
-1
+
b
-1
1
=
Z
1
1
eZ
3
Σ\Sigma
6
Y
1/2
1/2
Prob.
0.5
0.5
1 / 20