One output for binary classification and the loss function in this case

Regarding binary Classification, I have two question,

  1. Lets say, I only care about one class, If my model gives one output (using sigmoid) rather than two (using softmax), will it be a better idea. If so, could you please explain the reason?

  2. For one output, what loss function should I use? It seems that the PyTorch implementation of cross-entropy is not suitable for this. Because, according to the official document, as target I have to provide the indices of the correct classes and for one output that is not possible. What should I do in this case? Is there any option I am missing?

Answer to the question 2: use BCELoss

Hi Mainul!

It will be better to use a single output for a binary-classification
problem, rather than two (which you could logically do). By
doing so you eliminate one redundancy, and the parameters
that go along with it, from your network. This will provide at
least a modest advantage.

The natural loss function to use would be BCEWithLogitsLoss
without passing your output through a sigmoid(). If you insist,
for whatever reason, on using a sigmoid(), you would use

Good luck.

K. Frank

1 Like