Binary Cross Entropy

class liqfit.losses.BinaryCrossEntropyLoss

(multi_target=False, weight=None, reduction='mean')


  • multi_target (bool, optional): Whether the labels are multi-target or not.

  • weight (torch.Tensor, optional): Manual rescaling weight given to the loss of each batch element.

  • reduction (str, optional): Reduction method to apply on the loss. (Defaults to "mean").

Using CrossEntropyLoss

Simple wrapper over PyTorch's binary_cross_entropy_with_logits loss function to support multi-target inputs

from liqfit.losses import BinaryCrossEntropyLoss
import torch

x = torch.randn((1, 10, 20))
y = torch.randint(0, 2, (1, 10))
binary_loss = BinaryCrossEntropyLoss(multi_target=True)
loss = binary_loss(x, y) # No need for reshaping.

Last updated