Background
Sections
IntroductionModule 01 β€” Tensors 🧊01 Β· Creating Tensors 🧊02 Β· Indexing & Reshaping πŸ”ͺ03 Β· Tensor Math βž—04 Β· Device Placement πŸ–₯️⚑Module 02 β€” Autograd βš™οΈ01 Β· The Computational Graph πŸ•ΈοΈ02 Β· Backward Pass & Gradients ⬅️03 Β· Turning Autograd Off πŸ›‘04 Β· Gradient Gotchas πŸͺ€Module 03 β€” Neural Networks01 Β· The `nn.Module` Basics 🧱02 Β· Common Layers 🧩03 Β· Building a Network πŸ—οΈ04 Β· Inspecting Models πŸ”Module 04 β€” Data Handling πŸ—‚οΈ01 Β· Dataset Basics πŸ“‡02 Β· The DataLoader 🚚03 Β· Transforms 🎨04 Β· Splits & Built-in Datasets βœ‚οΈModule 05 β€” The Training Loop πŸ”01 Β· Loss Functions 🎯02 Β· Optimizers βš™οΈ03 Β· The Training Loop πŸ”04 Β· Evaluation & Metrics πŸ“ŠModule 06 β€” Saving & Loading πŸ’Ύ01 Β· `state_dict` Basics πŸ’Ύ02 Β· Checkpoints & Resuming ⏸️03 Β· Loading for Inference πŸš€04 Β· Best Model & Early Stopping πŸ…Module 07 β€” Computer Vision πŸ‘οΈ01 Β· Convolutions πŸ”²02 Β· CNN Architecture πŸ›οΈ03 Β· Transfer Learning πŸ”04 Β· Image Classification Project πŸ§ͺModule 08 β€” NLP & Transformers πŸ’¬01 Β· Text Data & Tokenization πŸ”€02 Β· Embeddings 🧭03 Β· Recurrent Layers & LSTMs πŸ”„04 Β· Intro to Transformers ⚑Module 09 β€” Ecosystem: PyTorch Lightning ⚑01 Β· Why Lightning? πŸ€”02 Β· The LightningModule 🧩03 Β· The Trainer πŸŽ›οΈ04 Β· DataModules & Callbacks 🧰Module 10 β€” Deployment & Optimization πŸš€01 Β· Exporting Models πŸ“¦02 Β· `torch.compile` ⚑03 Β· Inference Optimization πŸͺΆ04 Β· Serving & Next Steps πŸŽ“

Module 03 β€” Neural Networks

2 min read

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.Module and implementing forward().
  • Explain what nn.Linear, nn.ReLU, and nn.Dropout each 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