§6.2.2b–6.3Softmax Units · Other Output Types · Hidden Units Intro

Part II DL pp. 186–192 · ~4 min read

  • softmax output unit
  • heteroscedastic model
  • mixture density network

§6.2.2.3 Softmax units — for multinoulli outputs

To represent a distribution over nn classes, generalize the sigmoid to the softmax output unit . A linear layer produces unnormalized log-probabilities z=Wh+b\boldsymbol{z} = \boldsymbol{W}^\top\boldsymbol{h} + \boldsymbol{b} (zi=logP~(y=ix)z_i = \log \tilde P(y = i \mid \boldsymbol{x})), then softmax exponentiates and normalizes:

Term by term

softmax(z)i=exp(zi)jexp(zj),logsoftmax(z)i=zilogjexp(zj)\mathrm{softmax}(\boldsymbol{z})_i = \frac{\exp(z_i)}{\sum_j \exp(z_j)}, \qquad \log\mathrm{softmax}(\boldsymbol{z})_i = z_i - \log\sum_j \exp(z_j)
ziz_ithe first term of the LOG-softmax feeds the cost DIRECTLY and cannot saturate — so learning always has a signal to push zᵢ updirect term
logjexp(zj)maxjzj\log\sum_j \exp(z_j) \approx \max_j z_jpushes ALL logits down; roughly the max, so the NLL strongly penalizes the most-active INCORRECT classcompetition term
result\text{result}unregularized ML drives softmax to the empirical class FREQUENCIES (consistent estimator, §5.4.5)what it learns

Slide the logits and watch the competition — raising one class’s logit lowers the others’ probabilities (they must sum to 1), and the correct class’s cost stays responsive:

Softmax over three classes — logits → probabilities, with the log-softmax cost split into its two terms
01class 179%class 218%class 34%outlined bar = argmax (winner) · bars always sum to 100%

cost = −log softmax(z)1
= −(z1 − log Σ e^z)
= −(2.002.24) = 0.241

The first term z1 feeds the cost directly and can never saturate, so learning always has a signal — even when the second term becomes tiny.

Competition, saturation, and a name

Softmax is a winner-take-all / lateral-inhibition mechanism (outputs sum to 1, so one unit rising forces others down — like cortical neurons). It saturates when logit differences grow extreme; only losses that use a log to undo the exp (like the NLL) keep learning through that — squared error fails badly on softmax outputs. The name misleads: it softens arg max (a differentiable one-hot), not max; the soft max itself is softmax(z)z\mathrm{softmax}(\boldsymbol{z})^\top\boldsymbol{z}.

Two more facts. Shift invariance: softmax(z)=softmax(zmaxizi)\mathrm{softmax}(\boldsymbol{z}) = \mathrm{softmax}(\boldsymbol{z} - \max_i z_i) — the numerically stable form you met in §4.1’s stabilizer. Overparametrization: the nn outputs must sum to 1, so only n1n-1 are free; fixing zn=0z_n = 0 gives the restricted form, and the sigmoid is exactly softmax with a 2-D zz and z1=0z_1 = 0. In practice the overparametrized version is simpler and just as good.

§6.2.2.4 Other output types

The general recipe: let the network output ω=f(x;θ)\boldsymbol{\omega} = f(\boldsymbol{x}; \boldsymbol{\theta}) be the parameters of a distribution over yy, and use the loss logp(y;ω(x))-\log p(y; \boldsymbol{\omega}(\boldsymbol{x})). This covers a lot:

  • Learning the variance → a heteroscedastic model (the output variance depends on x\boldsymbol{x}). Use precision β=ζ(a)\boldsymbol{\beta} = \zeta(\boldsymbol{a}) (softplus for positivity) — the log-likelihood then involves only multiply/add/log, all well-behaved, whereas variance would need division (steep near 0) and standard deviation would need division and squaring (vanishing gradient near 0). Any covariance must stay positive definite (Σ=BB\boldsymbol{\Sigma} = \boldsymbol{B}\boldsymbol{B}^\top; full is O(d3)O(d^3), so diagonal is the norm).
  • Multimodal regression (several valid yy for one x\boldsymbol{x}) → a Gaussian-mixture output = a mixture density network :

Term by term

p(yx)=i=1np(c=ix)N(y;μ(i)(x),Σ(i)(x))p(y \mid \boldsymbol{x}) = \sum_{i=1}^n p(c = i \mid \boldsymbol{x})\, \mathcal{N}\big(y;\, \boldsymbol{\mu}^{(i)}(\boldsymbol{x}),\, \boldsymbol{\Sigma}^{(i)}(\boldsymbol{x})\big)
p(c=ix)p(c=i \mid \boldsymbol{x})mixture weights over the latent component c — a SOFTMAX output (positive, sums to 1)multinoulli
μ(i)(x)\boldsymbol{\mu}^{(i)}(\boldsymbol{x})per-component means — unconstrained (usually no output nonlinearity); ML weights each example by the probability that component produced itn×d means
Σ(i)(x)\boldsymbol{\Sigma}^{(i)}(\boldsymbol{x})per-component covariances — typically diagonal; gradients can be unstable (division by small variances) → clip gradientsn covariances

The three groups of outputs — mixing weights, means, covariances — all vary nonlinearly with x\boldsymbol{x}. This is exactly a conditional, input-dependent version of the Gaussian mixtures of §3.9.6:

A mixture output can place mass on several peaks at once (the fixed-input view of an MDN, fig 6.4)
0.67p(x)-4.50.04.5

P(x) = α·N(x; μ₁, σ²) + (1−α)·N(x; μ₂, σ²): the prior α = P(c=1) = 0.50 picks the component; merge the means and the modes fuse

Even richer outputs (sequences of characters forming a sentence) push beyond this chapter — recurrent nets (ch. 10) and Part III handle those.

§6.3 Hidden units — the decision unique to deep networks

Everything so far (cost, output units) is shared with linear models. The genuinely new choice is the hidden unit — and it is the least settled: an active research area with few definitive principles. The working guidance:

  • ReLU is an excellent default. When in doubt, use it.
  • Choose by experiment. Intuit a unit type, train, evaluate on the validation set — you generally cannot predict the winner in advance.
  • Most hidden units are the same shape: an affine map z=Wx+b\boldsymbol{z} = \boldsymbol{W}^\top\boldsymbol{x} + \boldsymbol{b} then an element-wise nonlinearity g(z)g(\boldsymbol{z}) — they differ only in gg.

Aside — the non-differentiable point (ReLU@0) is fine

ReLU isn’t differentiable at z=0z = 0 — which seems to disqualify it for gradient methods. In practice it’s a non-issue: training never actually reaches a point where the gradient is exactly 0 (it merely drives the cost low, fig 4.3), so minima at non-differentiable points are acceptable. Each such unit has a well-defined LEFT and RIGHT derivative (for ReLU@0: left = 0, right = 1); software just returns one of them — heuristically justified because the “0” input was probably a small value rounded to 0 anyway.

The catalog of hidden units — ReLU and its generalizations, the maxout unit, sigmoid/tanh, and the surprising failures — is next, along with how deep to stack them.

Check yourself — softmax, MDNs, hidden units

1.In log softmax(z)_i = z_i − log Σ exp(z_j), why does the first term keep learning alive?

2.In SoftmaxLab you raise z₁. What happens to the other classes' probabilities, and what property is this?

3.The name 'softmax' is a bit misleading. What does it actually soften?

4.Why parametrize a learned Gaussian output by PRECISION β = ζ(a) rather than by variance or standard deviation?

5.ReLU is not differentiable at z = 0. Why is that acceptable for gradient-based training?

5 questions