Map 1 · Building and training a network · Step 5
Choose the output and loss
How do I measure how wrong the network is?
Key formula
Fact or figure
Probability 0.95 on the correct class costs ; probability 0.01 costs . Confident mistakes are punished hard.
Skip this step and…
A softmax inside the model plus nn.CrossEntropyLoss applies softmax twice and distorts the gradients.
Digits example
10 logits → nn.CrossEntropyLoss; report accuracy, but train on cross-entropy.
Learn it
Taught in Section 6 (Loss Functions and Output Layers) of the course. The map follows the deep learning workflow, the order you build a model in; the course teaches in the order that is easiest to learn, so the numbers can jump.
- 6.1 Training as Minimising a LossTraining has two steps: choose a loss that measures how wrong the model is, then minimise it. Worked through for a straight line with mean squared error: the gradients, one update, and the loss going down.
- 6.2 MSE, MAE and Asymmetric LossesRegression losses compared: MSE punishes big errors hard and estimates the mean; MAE is robust to outliers and estimates the median; pinball losses price over- and under-prediction differently.
- 6.3 Softmax and Cross-entropySoftmax turns class scores into probabilities; cross-entropy scores those probabilities. A worked example, the numerical-stability trick, and the derivation of the famously simple gradient: predicted minus target.
- 6.4 Binary, Multi-class and Logits in PyTorchWhich output layer and loss go with which task, binary cross-entropy worked out, why accuracy can't be the training loss, the best accuracy any classifier can reach, and the logits rule that trips people up in PyTorch.
How it connects
Feeds into · Step 6
Compute the gradientsThe loss sets the output error that backprop starts from
How does each weight learn its share of the blame?
Builds on · Step 1
Frame the taskThe type of target decides the output layer and the loss
What should the network predict, and from what?
Builds on · Convolutional lane · step C3
Stack into a hierarchyDense layers and a softmax finish the network
How do layers build up from edges to objects?[conv → ReLU → pool] × several, then flatten → dense → output