Introduction to Deep Learning with PyTorch
Jasmin Ludolf
Senior Data Science Content Developer, DataCamp
$$
Hair | Feathers | Eggs | Milk | Fins | Legs | Tail | Domestic | Catsize | Class |
---|---|---|---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | 4 | 0 | 0 | 1 | 0 |
$$
$$
[-5.2, 4.6, 0.8]
import torch.nn.functional as F
print(F.one_hot(torch.tensor(0), num_classes = 3))
tensor([1, 0, 0])
print(F.one_hot(torch.tensor(1), num_classes = 3))
tensor([0, 1, 0])
print(F.one_hot(torch.tensor(2), num_classes = 3))
tensor([0, 0, 1])
from torch.nn import CrossEntropyLoss scores = torch.tensor([-5.2, 4.6, 0.8]) one_hot_target = torch.tensor([1, 0, 0])
criterion = CrossEntropyLoss()
print(criterion(scores.double(), one_hot_target.double()))
$$
tensor(9.8222, dtype=torch.float64)
Loss function takes:
Loss function outputs:
Introduction to Deep Learning with PyTorch