22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1

A Simple Regression Problem

Spoilers

In this chapter, we will:

• briefly review the steps of gradient descent (optional)

• use gradient descent to implement a linear regression in Numpy

• create tensors in PyTorch (finally!)

• understand the difference between CPU and GPU tensors

• understand PyTorch’s main feature, autograd, used to perform automatic

differentiation

• visualize the dynamic computation graph

• create a loss function

• define an optimizer

• implement our own model class

• implement nested and sequential models, using PyTorch’s layers

• organize our code into three parts: data preparation, model configuration, and

model training

Jupyter Notebook

The Jupyter notebook corresponding to Chapter 1 [39] is part of the official Deep

Learning with PyTorch Step-by-Step repository on GitHub. You can also run it

directly in Google Colab [40] .

If you’re using a local installation, open your terminal or Anaconda prompt and

navigate to the PyTorchStepByStep folder you cloned from GitHub. Then, activate

the pytorchbook environment and run jupyter notebook:

$ conda activate pytorchbook

(pytorchbook)$ jupyter notebook

60 | Chapter 1: A Simple Regression Problem

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!