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.

Figure 3.6 - Training and validation losses

"Wait, there is something weird with this plot." you say.

You’re right; the validation loss is lower than the training loss. Shouldn’t it be the

other way around?! Well, generally speaking, YES, it should, but you can learn more

about situations where this swap happens at this great post [71] . In our case, it is

simply that the validation set is easier to classify: If you check Figure 3.1 at the

beginning of the chapter, you’ll notice that the red and blue points in the right plot

(validation) are not as mixed up as the ones in the left plot (training).

Having settled that, it is time to inspect the model’s trained parameters:

print(model.state_dict())

Output

OrderedDict([('linear.weight', tensor([[ 1.1822, -1.8684]], device

='cuda:0')),

('linear.bias', tensor([-0.0587], device='cuda:0'))])

Our model produced logits, right? So we can plug the weights above into the

corresponding logit equation (Equation 3.3), and end up with:

Equation 3.18 - Model’s output

Model Training | 233

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

Saved successfully!

Ooh no, something went wrong!