0
$\begingroup$

My aim is to predict whether a person is alive or dead. In the case there are two classes which can either be alive (1) or dead (0). The output could be only one class i.e 1 or 0 and not multi label result.

I have one-hot encoded value for the label

label = [[0, 1], [1, 0], [0,1]]

And the model also predicts two raw logits as output.

output = [[2.0589, -2.0658], [-0.2345, 1.3540], [2.0589, -2.0658]]

I have seen many examples where binary cross entropy loss is used for only 1 output as label and output of the class. I am using PyTorch and I can find two implementation of binary cross entropy loss:

  1. BCELoss
  2. BCEWithLogitsLoss (This uses sigmoid + BCELoss)

I am aware about the activation function used but my issue is whether I can use binary cross entropy loss for values having one-hot encoded values or not?

$\endgroup$
4
  • $\begingroup$ Yes, all other terms except the positive class for an OHE will become zero. Loss of positive class will drive the Backpropagation $\endgroup$
    – 10xAI
    Commented Oct 16, 2020 at 5:55
  • $\begingroup$ @10xAI Could you elaborate what exactly you mean by "positive class for an OHE will become zero"? I am a bit confused whether you mean 0 as a positive prediction and 1 as a negative prediction with one-hot-encoding? $\endgroup$
    – PaladiN
    Commented Oct 16, 2020 at 6:17
  • $\begingroup$ −(ylog(p)+(1−y)log(1−p)) will become −(ylog(p)) . Since you will have only one Class=1 and rest all=0 in OHE. $\endgroup$
    – 10xAI
    Commented Oct 16, 2020 at 9:34
  • $\begingroup$ @10xAI Thanks, got it. But will that cause any issue, other than loss being assigned higher than on crossentropyloss? $\endgroup$
    – PaladiN
    Commented Oct 16, 2020 at 13:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.