

That brings me to the third reason why cross entropy is confusing.


For categorical cross entropy, the target is a one-dimensional tensor of class indices with type long and the output should have raw, unnormalized values. The output tensor should have elements in the range of and the target tensor with labels should be dummy indicators with 0 for false and 1 for true (in this case both the output and target tensors should be floats). The shapes of the target tensors are different. For binary cross entropy, you pass in two tensors of the same shape.It’s not a huge deal, but Keras uses the same pattern for both functions ( Binar圜rossentropy and CategoricalCrossentropy), which is a little nicer for tab complete. The naming conventions are different. The loss classes for binary and categorical cross entropy loss are BCELoss and CrossEntropyLoss, respectively.You can use categorical cross entropy for single-label categorical targets.īut there are a few things that make it a little weird to figure out which PyTorch loss you should reach for in the above cases. You can use binary cross entropy for single-label binary targets and multi-label categorical targets (because it treats multi-label 0/1 indicator variables the same as single-label one hot vectors). You have a multi-label categorical target.You have a single-label categorical target.There are three cases where you might want to use a cross entropy loss function:
