Hi Wjk!



 Wjk666:

So I need to control it before bceloss, is it right? Such as
score[score > 1.0] = 1.0



Yes, this is a sensible thing to do.
This could also be an appropriate use case for torch.clamp() 10.
Note, however, you should only be doing this if the result you are forcing
to be <= 1.0 should already be mathematically no greater than 1.0, and
only exceed 1.0 because of round-off error. (as in your toy example).  If in
your real use case the values you use as input for BCELoss could,
absent round-off error, be greater than 1.0, then you should fix that issue.
Simply clamping them to be no greater than 1.0 would just be sweeping
the real problem under the rug.
Best.
K. Frank