Hi Alice!



 Alice_NL:

For my output I wish to get probabilities. That is why I had sigmoid function at the end of forward. Now with using BCEWithLogitsLoss function I deleted the sigmoid function and my output can be negative and can be bigger than 1


Yes, without the Sigmoid activation function, the output of your
model will be raw-score so-called logits.  They run from -inf to
inf, and are what you want as the input to BCEWithLogitsLoss.
Sigmoid maps logits to probabilities that run from 0.0 to 1.0.
You may well want probabilities for certain purposes.  In such a case,
you still want your model to output logits (no Sigmoid) that you feed
to BCEWithLogitsLoss (and then backpropagate).  When you want
probabilities, just apply Sigmoid to your logits (separately from your
model, loss function, and backpropagation) to convert them to
probabilities for whatever subsequent processing you have.
A word of explanation:  The logits and probabilities contain the same
information and can be transformed mathematically back and forth
into one another.  For numerical reasons it’s better to pass logits
from your model to your BCEWithLogitsLoss loss function.
Best.
K. Frank