Your question is Implement Binary Focal Loss Gradients. 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 binary focal loss for logits and its gradient with respect to each logit. Given a list of real-valued logits logits, binary labels labels in {0,1}, focusing parameter gamma, balancing factor alpha, and reduction mode ("none", "sum", or "mean"), return both the forward loss and the backward gradient vector. Use a numerically stable sigmoid/log-sigmoid formulation.
def focal_loss_with_grad(logits, labels, alpha, gamma, reduction):