We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Loss Functions
PyTorchThe training objectives that shape every model — regression, classification, distribution-matching, and contrastive.
8 exercises
Explore freely. Sign in to keep your progress.
Your learning sequence
- 1 Not solved yet. Implement Mean Squared Error Practice · Easy
- 2 Not solved yet. Implement Binary Cross-Entropy Loss Practice · Medium
- 3 Not solved yet. Implement Cross-Entropy Loss Practice · Medium
- 4 Not solved yet. Implement KL Divergence Practice · Medium
- 5 Not solved yet. Label Smoothing Practice · Easy
- 6 Not solved yet. Focal Loss Practice · Medium
- 7 Not solved yet. Triplet Loss Practice · Medium
- 8 Not solved yet. Contrastive Loss (InfoNCE) 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 gamma greater than zero, how does the focal factor change the contribution of an example whose true-class probability is p_t?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
import math
gamma = 2.0
for p_t in (0.9, 0.1):
factor = (1 - p_t) ** gamma
loss = -factor * math.log(p_t)
print(f"{factor:.2f} {loss:.4f}")