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.

Model Configuration & Training

We can use our data loader that outputs packed sequences (train_var_loader) to

feed our SquareModelPacked model and train it in the usual way:

Model Configuration

1 torch.manual_seed(21)

2 model = SquareModelPacked(n_features=2, hidden_dim=2, n_outputs=1)

3 loss = nn.BCEWithLogitsLoss()

4 optimizer = optim.Adam(model.parameters(), lr=0.01)

Model Training

1 sbs_packed = StepByStep(model, loss, optimizer)

2 sbs_packed.set_loaders(train_var_loader)

3 sbs_packed.train(100)

fig = sbs_packed.plot_losses()

Figure 8.29 - Losses—SquareModelPacked

StepByStep.loader_apply(train_var_loader, sbs_packed.correct)

Variable-Length Sequences | 669

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

Saved successfully!

Ooh no, something went wrong!