When I run my data through a reset model for a binary classification, it returns the probability for each prediction (as the final node is using a softmax). Which is the first number of the binary probability returned, the 0 or 1 class?
Based on your question I assume you are using two output neurons for the binary classification task.
If that’s the case, your target basically defines which output neuron represents which class.
E.g. if your target is 0
for the current sample, output[0]
will represent the logit (or probability) for this class.
I’m not sure, which loss function you are using, but note that nn.CrossEntropyLoss
expects logits (no softmax at the end), while nn.NLLLoss
expects log probailities (log_softmax
at the end).
Alternatively, you could also use a single output neuron and apply nn.BCE(WithLogits)Loss
as the loss function.
So I’m wrong to have a LogSoftmax at the end and use CrossEntropyLoss?
Yes, since internally nn.CrossEntropyLoss
will apply F.log_softmax
and nn.NLLLoss
(line of code),
so you would have to chose between:
- raw logits (no activation function) +
nn.CrossEntropyLoss
-
F.log_softmax
+nn.NLLLoss