Using BCELoss() with real-valued labels without any correspondance to a class

Hi MngFrc!

Yes, this is a conventional binary-classification problem. The
input value for the parameter is either accepted – class-“1”,
“yes” – or refused – class-“0”, “no”. That is, the input has been
classified into one of two classes.

This is standard. The output of the classifier – a continuous
number between 0 and 1 – is understood as the predicted
probability of the input being in class-“1”. This is good for a
number of reasons, not least of which is that it is the result of
a differentiable computation and can be fed into a differentiable
loss function, so the model can be trained with back-propagation.

Yes. The key is that the continuous output of the model is to be
understood as the predicted probability of the input being in
class-“1”. And this is exactly what BCELoss expects.

(As an aside, for reasons of numerical stability, you’ll be better
off removing the Sigmoid and using BCEWithLogitsLoss.
This is mathematically – but not numerically – equivalent.)

Best.

K. Frank

1 Like