Deep Learning with PyTorch: Train Your First Neural Network

You build one small program that learns to read handwritten digits. It starts as a grid of numbers and two tensors of weights you write by hand, so nothing is a black box: you measure how wrong the model is, let PyTorch find which way to change every weight, and repeat that in a training loop. Then you build the network the usual PyTorch way, measure it honestly on images it never saw, save it and use it on a new image. It trains in a minute or two on a laptop CPU. You need basic Python and school maths.

What this course covers

  1. Deep Learning from the Outside: Examples In, Predictions Out: Explain what a neural network learns from and the cycle that trains it, and load a dataset of labelled images and read one of them as the numbers it is stored as.
  2. Tensors: Shapes and Types: Read the shape and type of any tensor and pick out one element, one row or a range of it by position.
  3. Maths on Whole Tensors: No Loops Needed: Rescale, reshape and summarise a whole tensor in single expressions, and say what shape and type each result has.
  4. A Model by Hand: Weights, Scores and a First Guess: Write a model as tensors of weights and biases, trace how an input becomes one score per class and a predicted class, and measure how often an untrained model is right.
  5. Loss: One Number for How Wrong the Model Is: Turn a model's scores into probabilities, work out the cross-entropy loss of a prediction by hand, and explain why training follows the loss and not the accuracy.
  6. Gradients: Which Way to Change Every Weight: Explain what a gradient tells you without calculus, have PyTorch compute the gradients of a loss, and lower the loss by repeating a gradient descent step written by hand.
  7. The Training Loop: Batches, Epochs and an Optimizer: Write a training loop that goes through the data in shuffled mini-batches for several epochs with an optimizer, say what each line does, and make the run give the same numbers every time.
  8. Build the Network: Layers, ReLU and nn.Module: Define a network with a hidden layer as a module, explain what the activation function between its layers is for, and train it with the loop you already have.
  9. Measure It Honestly: Validation, Test and Overfitting: Split data into training, validation and test sets, measure a model correctly on data it did not train on, and tell from the numbers when it has started to overfit.
  10. Save the Model and Predict a New Image: Save a trained network's weights, load them safely into a rebuilt network in another program, and use it to predict the class of a new input prepared the way the training data was.