Skip to content

Module 06

Anurag Prasad edited this page Nov 7, 2026 · 9 revisions

Module 06: Loss Functions, Gradient Descent and Empirical Risk Minimization

Level: Beginner–Intermediate
Status: Introductory technical chapter with supporting lessons and learning resources

Module purpose

This module is a self-contained learning unit within the larger Deep Learning curriculum. Its purpose is to build understanding from motivation and prerequisites through mathematical reasoning, implementation and critical evaluation.

Introduction and conceptual foundation

A learning algorithm needs a numerical objective that measures disagreement between predictions and targets. Empirical risk minimization averages this objective over observed examples, and gradient-based optimization adjusts parameters to reduce it. The choice of loss encodes assumptions about the task and error structure.

How the ideas develop

Distinguish regression and classification losses. Derive a small MSE or cross-entropy example, then study batch, stochastic and mini-batch gradient descent. Interpret learning rate, gradient scale, objective curvature and validation behaviour.

What the reader should be able to explain

By the end of this module, a reader should be able to define its central objects, explain the motivation behind its main methods, interpret the governing equations, work through a small example, and identify assumptions and limitations. The goal is understanding the mechanism—not memorizing a list of terms.

Learning outcomes

  • Select a loss for a task and output distribution.
  • Derive MSE and cross-entropy.
  • Explain empirical risk minimization.

Prerequisites and connections

Modules 02, 03 and 05 explain the calculus, probability and activation functions needed to understand learning objectives.

Useful background

Where these ideas are used next

Navigation

Focused submodules and topic extensions

The pages below provide focused treatments of substantial concepts that benefit from a separate explanation.

Topic-wise lessons

  1. Module-06-Lesson-01
  2. Module-06-Lesson-02
  3. Module-06-Lesson-03
  4. Module-06-Lesson-04
  5. Module-06-Lesson-05
  6. Module-06-Lesson-06
  7. Module-06-Lesson-07
  8. Module-06-Lesson-08
  9. Module-06-Lesson-09

How to complete this module

  1. Study the lessons in prerequisite order.
  2. Write a notation sheet and derive central equations.
  3. Solve at least one hand-worked example per major mechanism.
  4. Implement core operations where appropriate.
  5. Verify outputs and gradients.
  6. Complete conceptual and coding exercises.
  7. Record limitations and research extensions.

Completion status

  • Conceptual understanding
  • Mathematical derivations
  • Worked numerical examples
  • NumPy implementation (where applicable)
  • PyTorch implementation (where applicable)
  • Tests and numerical verification
  • Experiments and interpretation
  • Revision and self-assessment

Technical chapter

1. Why this area matters

Learning is framed as empirical risk minimization: choose parameters that minimize average loss on observed examples. Loss functions encode the task and the optimization objective; gradient descent supplies an iterative method for reducing that objective.

2. Core mathematical formulation

Empirical risk: $$ \hat R(\theta)=\frac1N\sum_{i=1}^{N}\ell(f_\theta(x_i),y_i). $$

Gradient descent: $$ \theta_{t+1}=\theta_t-\eta\nabla_\theta\hat R(\theta_t). $$

Binary cross-entropy for a logit z and label y: $$ \ell(z,y)=-y\log\sigma(z)-(1-y)\log(1-\sigma(z)). $$

3. Worked reasoning example

For squared error $L(w)=\frac12(w-2)^2$, at w=0 the gradient is -2. With learning rate 0.1, one update gives w=0.2. The objective falls from 2 to 1.62, illustrating a local descent step.

4. Conceptual flow

flowchart TD
  A[Training examples] --> B[Model predictions]
  B --> C[Task loss]
  C --> D[Average empirical risk]
  D --> E[Gradient computation]
  E --> F[Parameter update]
  F --> B
Loading

5. Implementation and verification

Compare MSE, MAE, binary cross-entropy and categorical cross-entropy on small hand-computable examples. Plot loss against a scalar parameter and verify the gradient numerically.

6. Common failure modes and misconceptions

The loss function is not the same as the evaluation metric. Learning rate controls step size, not model capacity. A lower training loss does not guarantee better generalization. Class imbalance may require weighting, resampling or a task-specific objective.

7. Advanced and research directions

Explore robust losses, focal loss, label smoothing, calibration-aware objectives, distributionally robust optimization and bilevel optimization.

8. Suggested practical assignment

  1. Reproduce the smallest mathematical example by hand.
  2. Implement the central operation using NumPy.
  3. Implement the same operation using PyTorch.
  4. Compare outputs and gradients with numerical tolerances.
  5. Change one assumption or hyperparameter and document what changes.
  6. Record environment, random seed, data split, compute budget and limitations.

9. Completion criteria

  • Explain the motivation and assumptions without notes.
  • Derive the principal equations and define every symbol.
  • Complete at least one worked numerical example.
  • Trace tensor shapes through the computation.
  • Implement and test the central mechanism.
  • Explain at least two failure modes.
  • Read one primary paper and summarize its contribution and limitations.

Content status: This page now contains a technical chapter and a practical learning specification. The linked lesson pages provide focused subtopic treatment; experiments are not claimed complete until their result logs are added.

🎓 Deep Learning Hub

🏠 Home · 🗺️ Curriculum · 🧭 Learning paths

❓ Question bank · 📖 Glossary · 📚 References

Jump to module:

01 02 03 04 05 06 07 08 09 10 11 12

13 14 15 16 17 18 19 20 21 22 23 24

Part 1 · Mathematical foundations
Part 2 · Neural network fundamentals
Part 3 · Training deep networks
Part 4 · Core architectures
Part 5 · Representation and generative learning
Part 6 · Specialised, modern and responsible deep learning
Reference and meta

Clone this wiki locally