Introduction au deep learning avec PyTorch
Jasmin Ludolf
Senior Data Science Content Developer, DataCamp
$$
Poils | Plumes | Œufs | Lait | Nageoires | Pattes | Queue | Domestique | Taille du chat | Classe |
---|---|---|---|---|---|---|---|---|---|
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)
La fonction de perte prend :
Résultats de la fonction de perte :
Introduction au deep learning avec PyTorch