0
votes

In the pytorch docs, it says for cross entropy loss:

input has to be a Tensor of size (minibatch, C)

Does this mean that for binary (0,1) prediction, the input must be converted into an (N,2) tensor where the second dimension is equal to (1-p)?

So for instance if I predict 0.75 for a class with target 1 (true), would I have to stack two values (0.75; 0.25) on top of each other as input?

1
You can also check out this topic, if you're interested in how it is calculated: stackoverflow.com/questions/51822974/…MBT

1 Answers

0
votes

Quick and easy: yes, just give 1.0 for the true class and 0.0 for the other class as target values. Your model should also generate two predictions for that case, though it would be possible to do that with only a single prediction and use the sign information to determine the class. In that case, you wouldn't get a probability using a softmax as the last operation but for example by using a sigmoid function (which maps your output from (-inf,inf) to (0,1).