Loss Functions, Behaviors & Selection Questions
Loss function design, evaluation, and selection in machine learning. Includes common loss functions (MSE, cross-entropy, hinge, focal loss), how loss properties affect optimization and gradient flow, issues like class imbalance and label noise, calibration, and practical guidance for choosing the most appropriate loss for a given task and model.
MediumTechnical
88 practiced
Implement multi-class focal loss in PyTorch for logits input. Signature: def focal_loss_logits(logits, targets, gamma=2.0, alpha=None, reduction='mean'): where targets are integer class indices. Explain handling alpha as class weights, use log-softmax for numerical stability, and support different reduction modes.
EasyTechnical
73 practiced
Compare Mean Squared Error (MSE) and Mean Absolute Error (MAE) for regression tasks. Describe how each loss affects gradient magnitude, sensitivity to outliers, and optimization dynamics. Give practical guidelines for production: when to prefer MSE, MAE, or Huber loss; how to choose the Huber delta; and implications for monitoring and robustness.
HardTechnical
79 practiced
Design a loss-level approach to enforce equalized odds across demographic groups in a classifier. Describe converting fairness constraints into Lagrangian-penalty terms, discuss optimization challenges from non-convexity, and propose monitoring, rollback, and stakeholder communication strategies for production deployments where fairness and accuracy trade-offs must be justified.
MediumTechnical
76 practiced
In sequence-to-sequence tasks (e.g., machine translation), explain why one might move from token-level cross-entropy training to sequence-level objectives (e.g., BLEU optimization via REINFORCE or Minimum Risk Training). Describe the pros and cons and practical methods to stabilize sequence-level training such as variance reduction and mixing token- and sequence-level losses.
EasyTechnical
82 practiced
What is label smoothing? Explain how replacing one-hot labels with softened targets affects training, gradient flow, and model calibration. Provide an explicit example: for a 5-class problem with smoothing epsilon=0.1, show the target distribution for the true class and others, and discuss practical benefits and drawbacks such as reduced overconfidence and potential effect on transfer learning.
Unlock Full Question Bank
Get access to hundreds of Loss Functions, Behaviors & Selection interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.