Loss Functions and Backpropagation
Related: 4. Deep Learning and FCNs | 5. Activation Functions | 7. Evaluating ML Models | 8. Convolutional Neural Networks | Artificial Intelligence
Loss Functions
The loss function measures how badly the AI system performed:
The total loss over the training set:
Binary Cross-Entropy (BCE)
For binary classification (output via sigmoid):
Categorical Cross-Entropy (CCE)
For multi-class classification (output via softmax):
Mean Squared Error (MSE)
For regression (see also 15. Regression and Text Classification with FCNs):
Summary: Loss + Output Activation Pairing
| Task | Output Activation | Loss Function |
|---|---|---|
| Binary classification | Sigmoid | Binary cross-entropy |
| Multi-class classification | Softmax | Categorical cross-entropy |
| Regression | Linear (none) | Mean squared error |
Gradient Descent and Backpropagation
Gradient — indicates the direction and rate of steepest ascent of the error function. To minimise the loss, we move in the opposite direction of the gradient.
Backpropagation computes the gradient of the loss with respect to each weight using the chain rule.
Weight update rule:
where is the learning rate.
SGD vs Mini-Batch SGD
| SGD | Mini-Batch SGD | |
|---|---|---|
| Samples per update | 1 random sample | A batch of samples |
| Gradient estimate | Noisy | Smoother |
| Speed | Fast per step | More stable convergence |
Training loop: Input → Predict → Error → Backprop → Update → Repeat
Dropout (Regularisation)
Dropout randomly drops (zeroes out) some neuron outputs during training with probability . This prevents overfitting (see 7. Evaluating ML Models) by making the model less sensitive to noise and more generic.
model.add(Dropout(0.3)) # 30% dropout probabilityOptimisers
| Optimiser | Description |
|---|---|
| SGD | Basic stochastic gradient descent |
| RMSprop | Adapts learning rate per parameter |
| Adam | Combines momentum and adaptive learning rates; often the default choice |