Your question is Focal Loss Implementation. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Implement focal loss.
Asked in the First Round Interview stage. Coding section instead of expected LeetCode style algorithmic problems.
Implement focal_loss(logits, targets, alpha, gamma). Inputs are equal-length arrays of binary classification logits and labels, where each label is 0 or 1. Use alpha for positive examples and 1 - alpha for negative examples. Return the mean binary focal loss as a float:
-alpha_t * (1 - p_t) ** gamma * log(p_t)
Compute the expression stably from logits rather than relying on probabilities that may underflow or overflow.
def focal_loss(logits, targets, alpha, gamma):