kaira.losses.text.CrossEntropyLoss

Inheritance diagram of CrossEntropyLoss

Inheritance diagram for CrossEntropyLoss

class kaira.losses.text.CrossEntropyLoss(weight=None, ignore_index=-100, label_smoothing=0.0)[source]

Bases: BaseLoss

Cross Entropy Loss Module.

This module calculates the cross entropy loss for classification tasks.

Methods

__init__

Initialize the CrossEntropyLoss module.

forward

Forward pass through the CrossEntropyLoss module.

__init__(weight=None, ignore_index=-100, label_smoothing=0.0)[source]

Initialize the CrossEntropyLoss module.

Parameters:
  • weight (torch.Tensor, optional) – Class weights. Default is None.

  • ignore_index (int) – Index to ignore. Default is -100.

  • label_smoothing (float) – Label smoothing value. Default is 0.0.

forward(x: Tensor, target: Tensor) Tensor[source]

Forward pass through the CrossEntropyLoss module.

Parameters:
Returns:

The cross entropy loss.

Return type:

torch.Tensor