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.

Imports

For the sake of organization, all libraries needed throughout the code used in any

given chapter are imported at its very beginning. For this chapter, we’ll need the

following imports:

import numpy as np

import torch

import torch.optim as optim

import torch.nn as nn

import torch.nn.functional as F

from torch.utils.data import DataLoader, Dataset, random_split, \

TensorDataset

from torch.nn.utils import rnn as rnn_utils

from data_generation.square_sequences import generate_sequences

from stepbystep.v4 import StepByStep

Sequences

In this third part of the book, we’ll dive into a new kind of input: sequences! So far,

each data point has been considered in and of itself; that is, each data point has had

a label to call its own. An image of a hand was classified as "rock," "paper," or

"scissors" based on its pixel values alone, without paying any attention to other

images' pixel values. This won’t be the case anymore.

In sequence problems, an ordered sequence of data points shares a single

label—emphasis on being ordered.

"Why is ordered so important?"

If the data points aren’t ordered, even if they share a single label, they are not a

sequence, but rather a collection of data points.

Let’s think of a slightly contrived example: greyscale images with shuffled pixels.

Each pixel has a single value, but a pixel alone doesn’t have a label. It is the

collection of shuffled pixels, the shuffled image, that has a label: a duck, a dog, or a

cat (labeled before shuffling the pixels, of course).

588 | Chapter 8: Sequences

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

Saved successfully!

Ooh no, something went wrong!