Introduction to deep learning with PyTorch

Introduction to Deep Learning with PyTorch

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

Deep learning is everywhere!

Illustration showing multiple languages around a globe

Introduction to Deep Learning with PyTorch

Deep learning is everywhere!

Illustration showing multiple languages around a globe, and a self driving car

Introduction to Deep Learning with PyTorch

Deep learning is everywhere!

Illustration showing multiple languages around a globe, a self driving car, and medical diagnosis

Introduction to Deep Learning with PyTorch

Deep learning is everywhere!

Illustration showing multiple languages around a globe, a self driving car, and medical diagnosis

Introduction to Deep Learning with PyTorch

What is deep learning?

An onion diagram representing deep learning as a subset of machine learning

A diagram of a small neural network

Introduction to Deep Learning with PyTorch

What is deep learning?

An onion diagram representing deep learning as a subset of machine learning

A diagram of a neural network with multiple layers

Introduction to Deep Learning with PyTorch

Deep learning networks

$$

  • Inspired by how the human brain learns

An illustration of a person studying the brain

Introduction to Deep Learning with PyTorch

Deep learning networks

$$

  • Inspired by how the human brain learns
  • Neurons ➡ neural networks
  • Models require large amount of data
  • At least 100,000s data points

An illustration of a person studying the brain, with a focus on neurons

Introduction to Deep Learning with PyTorch

PyTorch: a deep learning framework

$$

$$

  • One of the most popular frameworks
  • Originally developed by Meta AI, now part of Linux Foundation
  • Intuitive and user-friendly
  • Similarities with NumPy

 

The PyTorch logo

Introduction to Deep Learning with PyTorch

PyTorch tensors

$$

  • Tensor:
    • Similar to array or matrix
    • Building block of neural networks

$$

import torch

my_list = [[1, 2, 3], [4, 5, 6]] tensor = torch.tensor(my_list) print(tensor)
tensor([[1, 2, 3],
        [4, 5, 6]])
Introduction to Deep Learning with PyTorch

Tensor attributes

  • Tensor shape
my_list = [[1, 2, 3], [4, 5, 6]]
tensor = torch.tensor(my_list)
print(tensor.shape)
torch.Size([2, 3])
  • Tensor data type
print(tensor.dtype)
torch.int64
Introduction to Deep Learning with PyTorch

Getting started with tensor operations

Compatible shapes

a = torch.tensor([[1, 1], 
                  [2, 2]])

b = torch.tensor([[2, 2], 
                  [3, 3]])
  • Addition / subtraction
print(a + b)
tensor([[3, 3],
        [5, 5]])

Incompatible shapes

a = torch.tensor([[1, 1], 
                  [2, 2]])

c = torch.tensor([[2, 2, 4], 
                  [3, 3, 5]])
  • Addition / subtraction
print(a + c)
RuntimeError: The size of tensor a
(2) must match the size of tensor b (3) 
at non-singleton dimension 1
Introduction to Deep Learning with PyTorch

Element-wise multiplication

a = torch.tensor([[1, 1], 
                  [2, 2]])
b = torch.tensor([[2, 2], 
                  [3, 3]])
print(a * b)
tensor([[2,  2],
        [6, 6]])
Introduction to Deep Learning with PyTorch

Matrix multiplication

Matrix multiplication

Introduction to Deep Learning with PyTorch

Matrix multiplication

Matrix multiplication highlighted

$$

  • $1 \cdot 2 + 1 \cdot 3 = 5$

$$

  • Perform addition and multiplication to process data and learn patterns
Introduction to Deep Learning with PyTorch

Let's practice!

Introduction to Deep Learning with PyTorch

Preparing Video For Download...