All courses Machine learning

Deep Learning with PyTorch: Train Your First Neural Network

Beginner

Teach a small network to read handwritten digits, from tensors to a saved model.

Beginner 10 lessons 32 lab exercises Certificate Updated

You build

A command-line program that trains a small neural network on the MNIST images of handwritten digits, measures it on images it never saw, saves it, and says which digit is in an image file.

You need

  • Writing basic Python: variables, lists, loops and functions, and importing a module. A class is written once in the course and explained as it is used.
  • Running a Python script from a terminal
  • School mathematics: arithmetic, averages and percentages. No calculus or linear algebra is needed.

To build it on your own machine

This is optional and comes with a plan. The course pack brings the starting files, a ready container and a check for every lesson. You need only Docker and git, plus your own AI coding agent if you want a tutor.

What you learn

The model, the loss and the update step, written by you once before PyTorch does them for you.

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.

  • Data as Tensors. An image is a grid of numbers, and a tensor holds thousands of them with one shape and one type. Reading shapes and working on whole tensors at once is the skill every later step uses.
  • A Loss and Its Gradients. One number says how wrong the model is, and its gradient says which way to move each weight to make it smaller. PyTorch works the gradients out for you, and you learn what it is doing when it does.
  • The Training Loop. Predict, measure, find the gradients, update, and again: the same few lines train this network and the largest ones. Batches, epochs and an optimizer are the parts that make it practical.
  • Honest Measurement. A model is judged on data it never trained on. Validation data guides your choices, test data gives the final number once, and the gap between training and validation shows overfitting.

Lessons

Where it fits

Course 2 of 2 on the Machine Learning Engineer path.

How our courses are made Report a mistake