Computing sigmoid first can round extreme logits to exact probabilities of zero or one before BCE sees them. A production loss avoids that irreversible step: it scores raw logits directly using an equivalent expression whose exponential never grows.
Implement bce_with_logits_loss(z, y) without calling sigmoid. Theory gives the fused per-sample expression and explains why the exponent must receive a non-positive value.
z and binary y have matching shapes.float.exp on a positive value.np.maximum(z, 0), np.log1p, and np.exp(-np.abs(z)).Open one at a time. Each gives away a little more than the last.
Separate the expression into a piecewise-linear correction and a small logarithmic remainder.
-np.abs(z) is never positive; take its exponential, then use log1p for the logarithmic term.
No results yet
Run your code to check it against the examples, or submit to run every test.