22.02.2024 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Data Generation

1 test_points, test_directions = generate_sequences(seed=19)

Data Preparation

There is nothing special about it: typical data preparation using a tensor dataset

and data loaders that will yield batches of sequences with shape (N=16, L=4,

F=2).

Data Preparation

1 train_data = TensorDataset(

2 torch.as_tensor(points).float(),

3 torch.as_tensor(directions).view(-1, 1).float()

4 )

5 test_data = TensorDataset(

6 torch.as_tensor(test_points).float(),

7 torch.as_tensor(test_directions).view(-1, 1).float()

8 )

9 train_loader = DataLoader(

10 train_data, batch_size=16, shuffle=True

11 )

12 test_loader = DataLoader(test_data, batch_size=16)

Model Configuration

The main structure behind the SquareModel is fairly simple: a simple RNN layer

followed by a linear layer that works as a classifier producing logits. Then, in the

forward() method, the linear layer takes the last output of the recurrent layer as

its input.

616 | Chapter 8: Sequences

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

Saved successfully!

Ooh no, something went wrong!