Hi Julia!



 julliet:

I’m using BCEWithLogitsLoss() for Loss, so I’m not implementing any Softmax on the layers.
Predictions of the model look something like this:
-0.2443,   6.6122,  25.0909,  ..., -62.7383,   0.3066,  61.6255
So I can’t really compare it to zeroes and ones of my label.
…
            nn.Linear(256, n_classes)



In terms of comparing your predictions to the “zeroes and ones” of
your label, BCEWithLogitsLoss does precisely this (without converting
your predictions into 1s and 0s).
BCEWithLogitsLoss takes predictions that are raw-score logits
(such as those produced by your final Linear layer and that run
from -inf to inf) and compares them with ground-truth labels that
are zeros and ones (or more generally, with ground-truth labels that
are probabilities between zero and one).  That is, not converting your
predictions (that are logits) into zeros and ones before passing them
to BCEWithLogitsLoss is the correct thing to do.  (In this situation,
BCEWithLogitsLoss will likely be your loss function used for training.)


how I should convert my predictions into 1s and 0s?


On the other hand, if you wish to compute the accuracy of your
predictions (an evaluation metric that you would most likely not use
for training), that is, the percentage of your yes-no predictions are
correct, you do want to convert your predictions to zeros and ones,
and then simply count how many are equal to your zero-and-one
ground-truth labels.
A logit of 0.0 corresponds to a probability (of being in the “1”-class)
of 0.5, so one would typically threshold the logit against 0.0:
accuracy = ((predictions > 0.0) == labels).float().mean()

Best.
K. Frank