Given raw (pre-sigmoid) logits and binary target (0s and 1s), return the
mean binary cross-entropy loss: for each element, `-(target * log(p) + (1 - target)
wherep = sigmoid(logit), averaged over all elements. Compute it in a numerically stable way directly from the logits rather than from sigmoid(logits)`.Input
logits = tensor([ 2.0000, -1.0000, 0.5000, -3.0000])
target = tensor([1., 0., 1., 0.])
Output
tensor(0.2407)