Introductie tot Deep Learning met PyTorch
Jasmin Ludolf
Senior Data Science Content Developer, DataCamp
$$

| Haar | Veren | Eieren | Melk | Vinnen | Poten | Staart | Tam | Katgrootte | Klasse |
|---|---|---|---|---|---|---|---|---|---|
| 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)
De verliesfunctie neemt:
De verliesfunctie geeft terug:

Introductie tot Deep Learning met PyTorch