We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Classifiers from Scratch
PyTorchBuild the simplest classifiers end-to-end — binary, multi-class, and sequence.
5 exercises
Explore freely. Sign in to keep your progress.
What you’ll build
- Binary and multiclass predictions with a loss you can explain.
- A recurrent classifier that carries information across tokens.
- A training loop that restores the best validation checkpoint.
Before you start
You should be comfortable with tensor shapes, matrix multiplication and basic derivatives. Begin with the forward passes, then put them to work in the training exercises.
Explore foundational tracks →Your learning sequence
- 1 Not solved yet. Binary Classifier Practice · Easy
- 2 Not solved yet. Multi-Class Classifier Practice · Easy
- 3 Not solved yet. Sequence Classifier Practice · Medium
- 4 Not solved yet. Train Binary Classifier End-to-End Practice · Medium
- 5 Not solved yet. Train Multiclass Classifier with Early Stopping Practice · Medium
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
For ten classes, what target distribution does label_smoothing=0.1 use for class 0?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
import torch
import torch.nn.functional as F
logits = torch.arange(10, dtype=torch.float32).unsqueeze(0)
target = torch.tensor([0])
soft_target = 0.9 * F.one_hot(target, num_classes=10).float() + 0.1 / 10
loss = F.cross_entropy(logits, target, label_smoothing=0.1)
manual = -(soft_target * logits.log_softmax(dim=1)).sum(dim=1).mean()
print([round(v, 2) for v in soft_target[0].tolist()])
print(torch.allclose(loss, manual))