Skip to course content
Free PyTorch course

Advanced Deep Learning with PyTorch

Module 02 Summary

The idea this module was built around

The first dimension is the batch. Most PyTorch errors are shape errors, and most shape errors are a lost or mismatched batch dimension.

What you can now do

The trap this module removed

An (n,) target against an (n, 1) prediction does not error. It broadcasts to (n, n), the loss trains on a matrix of pairwise differences, and the model appears to learn while optimising nonsense.

Figures worth remembering

20 items at batch size 6 gives four batches, the last holding 2. drop_last=True discards them.

Before you move on

Print the shape of both operands before any loss computation. It costs one line and catches the quietest bug in this course.