Cross-entropy weighs every example the same. In a dataset dominated by easy negatives, that means the loss is mostly spent on examples the model already gets right, drowning out the few hard ones. Focal loss down-weights the easy, well-classified examples so training focuses on what's still wrong.
Let p_t be the model's predicted probability for the true class:
Task: write focal_loss(y_true, y_pred, alpha, gamma) for binary labels, returning the mean loss, rounded to 4 decimal places.
p_t is y_pred when the true label is 1, and 1 - y_pred when it's 0.gamma = 0 collapses focal loss back to plain weighted cross-entropy — there's no down-weighting left.