Output Functions and Loss Functions — Linear, Softmax, Squared Error, Cross-Entropy
On this page 7 headings
Turn two scores into probabilities and a loss
Two class scores are 0 and ln(3). The correct class is the second one. Use natural logarithms.
Exponentiate the scores.
Normalise by their sum.
Cross-entropy uses the probability assigned to the correct class.
What changed? Softmax compares scores; cross-entropy rewards high probability on the correct class.
Quick check: What would the loss be if the first class were correct instead?
−ln(0.25) ≈ 1.3863: assigning the correct class only 25% probability is penalised more.
Swipe long formulas, tables or code sideways to see the rest.
Start here What the network should output depends on the question. Predicting a rating (a real number) needs a different last layer and a different loss than picking one fruit out of four. This page gives the two standard pairs you will use again and again: linear + squared error and softmax + cross-entropy.
Lecture example — movie ratings Input: movie features (isActorDamon, isDirectorNolan, …). Output: three ratings, (IMDb rating, critics’ rating, RT rating). .
Loss: the loss should measure how is from y. For real-valued outputs, squared error does this:
Output function: can O be the logistic (sigmoid)? No. Sigmoid squashes everything into (0, 1), but a rating like 8.2 is outside that range. So use a linear output:
is not stuck between 0 and 1.
Lecture example — fruit image Classify an image as one of 4 classes: Apple, Mango, Orange, Banana. If it is an apple, the true label is .
We could use squared error, but there is a better choice.
Notice: y is a probability distribution (all values , total ). should also be a probability distribution.
- is positive → every .
- Dividing by the total → they add up to 1.
Worked numbers: for [apple, mango, orange].
- [0.659, 0.242, 0.099]
- Check: ✔
Since only for the true class ℓ and 0 for all others, every term except one vanishes:
So for classification we:
minimise _ℓ or equivalently maximise _ℓ
| _ℓ (probability of true class) | Loss _ℓ |
|---|---|
| 0.9 | 0.105 |
| 0.659 | 0.417 |
| 0.5 | 0.693 |
| 0.1 | 2.303 |
(log here is the natural log, ln.)
_ℓ a function of ? Yes:
It is the probability that x belongs to class ℓ. We want to push it close to 1. _ℓ is called the log-likelihood of the data.
| Output type | Output activation | Loss function |
|---|---|---|
| Real values | Linear | Squared error |
| Probabilities | Softmax | Cross-entropy |
Other loss functions exist for other problems, but these two are by far the most common. For the rest of the backpropagation derivation we use softmax output + cross-entropy loss.
(The lecture also links a separate video on Information and Entropy for the background of cross-entropy.)
In one line: Use a linear output with squared error for real-valued targets, and a softmax output with cross-entropy (−log of the true class’s probability) for classification.
Exam words: linear output, squared error loss, softmax, probability distribution, one-hot label, cross-entropy, _ℓ, log-likelihood.
