Losses practice problems

12 problems · 0 solved

A loss function tells the model how wrong it is, and its gradient tells it how to improve. The choice of loss shapes what the model learns, and a careless implementation can overflow or quietly ignore part of the data. These problems ask you to write common losses from raw logits with attention to numerical stability. You will compute binary cross-entropy from logits, cross-entropy with label smoothing, class-weighted cross-entropy, the multiclass hinge loss and the soft Dice loss, down-weight easy examples with focal loss, compute a token-level distillation KL that ignores padding, compute batch-hard triplet loss, train embeddings with the InfoNCE loss, compute a symmetric contrastive loss and its gradient, and compute the supervised contrastive loss. Start with the Easy problems on binary cross-entropy and label smoothing. Then do weighted, focal and distillation losses, and finish with the contrastive family. Interviewers often ask why cross-entropy is computed from logits or when to use focal loss, and in practice the right loss can fix class imbalance or poor embeddings faster than a bigger model.

Easy 5

Medium 4

Hard 3

Related topics

All practice problems