Video by freeCodeCamp.org · taught by Aakash N S · streamed from YouTube. All rights remain with the creator.
Lesson 2: Tensors, Gradients and Linear Regression
About this lesson
This first session of the six-part Deep Learning with PyTorch live course, taught by Aakash N S, the co-founder of Jovian, lays the foundations that every later session builds on. It begins with an introduction to Jupyter notebooks and to doing data science in Python, showing how to run code in the cloud and keep a record of your work as you go. The session then introduces PyTorch tensors, showing how to create numbers, vectors, matrices and higher-dimensional tensors and how to perform operations on them. It explains how PyTorch computes gradients automatically for any calculation made with tensors, which is the feature that makes training neural networks practical, and how tensors and NumPy arrays can be converted into each other so that the two libraries work together. The second half applies these ideas to linear regression. You build the model from scratch using only tensor operations, with weights and biases, measure its predictions with the mean squared error loss, and use gradient descent, with gradients computed by autograd, to train it step by step until its predictions improve. The session then rebuilds the same model with PyTorch's built-in tools, such as the linear layer, ready-made loss functions, datasets, data loaders and optimisers, showing how much shorter and more reliable the code becomes. Each step is shown running live in a notebook. Afterwards, read Chapter 2 of the course book, which works a gradient descent step by hand.