Skip to content

cross_entropy_loss_from_proba

Cross entropy loss from probabilities.

CrossEntropyLossFromProbabilities #

Cross entropy form probabilities, because torch adds softmax/sigmoid inside BCE loss.

forward(inputs: Tensor, target: Tensor, nll_weights: Tensor | None = None) -> Tensor #

Forward computing of cross entropy form probabilities.

Source code in src/xpdeep/model/zoo/cross_entropy_loss_from_proba.py
def forward(self, inputs: Tensor, target: Tensor, nll_weights: Tensor | None = None) -> Tensor:
    """Forward computing of cross entropy form probabilities."""
    eps = torch.finfo(inputs.dtype).eps
    return nll_loss(torch.log(inputs + eps), torch.argmax(target, 1), weight=nll_weights, reduction=self.reduction)