Module 03 β Neural Networks
Time to assemble tensors and autograd into an actual model. This is where PyTorch starts to feel like deep learning.
So far you've learned the two raw ingredients: tensors (Module 01) hold the numbers, and autograd (Module 02) computes the gradients that let those numbers improve. A neural network is what you get when you organize thousands of tracked parameters into layers, stack those layers into a structure, and define how data flows through them. PyTorch gives you a clean, reusable framework for exactly this: the nn.Module class.
The key idea to carry in from Module 02 is that a network is not magic β it's just a tidy container for nn.Parameter tensors (tensors with requires_grad=True) plus a forward() method describing the math. Layers like Linear create and manage those parameters for you, autograd tracks them automatically, and nn.Module handles the bookkeeping β collecting every parameter, moving them to a device, and switching between training and evaluation modes. Learn this pattern once and you'll reuse it for every model in the rest of the course, from CNNs to Transformers.
This module is split into three sub-modules β work through them in order.
π Sub-Modules
| # | Sub-Module | What you'll learn |
|---|---|---|
| 01 | The nn.Module Basics |
Subclassing nn.Module, registering layers in __init__, and defining forward() |
| 02 | Common Layers | nn.Linear, activation functions like nn.ReLU, and regularization with nn.Dropout |
| 03 | Building a Network | Composing layers into a full model with nn.Sequential and a custom MLP |
| 04 | Inspecting Models | .parameters(), state_dict, train()/eval(), and moving a model to a device |
π― By the end of this module, you'll be able to...
- Define your own model by subclassing
nn.Moduleand implementingforward(). - Explain what
nn.Linear,nn.ReLU, andnn.Dropouteach do and why you'd use them. - Build a complete multi-layer network, run a forward pass, and inspect its parameters.
- Inspect a model's parameters and
state_dict, move it to a device, and toggle train/eval mode.
β Prerequisites
Tensors and tensor math from Module 01, and a solid grasp of requires_grad and nn.Parameter from Module 02 β especially the "from tensors to parameters" bridge in sub-module 04.
β¬ οΈ Prev module: 02 Β· Autograd Β· β‘οΈ Next module: 04 Β· Data Handling