Hi am having a binary classification problem and using BCELossWithLogits. However, my predictions are negative values (e.g. [-0.263, -0.308, -0.449, -0.279]
). Before, when I was using BCELoss with Sigmoid, I received probabilities as output as I was expecting. I am using auc_roc_score to compare the predictions to my targets (which are either 0 or 1). I read the docs and it says that the output of BCELossWithLogits is the negative logarithm of the sigmoid (but the example stills shows a positive value). Does someone know how I have to modify my predictions in order to get the probabilities or am I doing something wrong?
nn.BCEWithLogitsLoss
expects logits (as given in the name), which are unbounded and can contain values in [-Inf, Inf]
(of course they should contain valid values, since an Inf
output would also yield an invalid loss value). If you want to convert these logits to probabilities for further processing, you could use torch.sigmoid
on them. Note that you should not pass the probabilities (sigmoid outputs) to the criterion, but the logits.
The output of nn.BCEWithLogitsLoss
is the binary cross-entropy loss and would take values in [0,+Inf]
for the expected inputs.