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

TaskOutput ActivationLoss Function
Binary classificationSigmoidBinary cross-entropy
Multi-class classificationSoftmaxCategorical cross-entropy
RegressionLinear (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

SGDMini-Batch SGD
Samples per update1 random sampleA batch of samples
Gradient estimateNoisySmoother
SpeedFast per stepMore 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 probability

Optimisers

OptimiserDescription
SGDBasic stochastic gradient descent
RMSpropAdapts learning rate per parameter
AdamCombines momentum and adaptive learning rates; often the default choice