Skip to content
← All PyTorch tracks

Loss Functions

PyTorch

The 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. 1 Not solved yet. Implement Mean Squared Error Practice · Easy
  2. 2 Not solved yet. Implement Binary Cross-Entropy Loss Practice · Medium
  3. 3 Not solved yet. Implement Cross-Entropy Loss Practice · Medium
  4. 4 Not solved yet. Implement KL Divergence Practice · Medium
  5. 5 Not solved yet. Label Smoothing Practice · Easy
  6. 6 Not solved yet. Focal Loss Practice · Medium
  7. 7 Not solved yet. Triplet Loss Practice · Medium
  8. 8 Not solved yet. Contrastive Loss (InfoNCE) Practice · Medium

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

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}")
Question 1 of 4