kaira.losses.text.LabelSmoothingLoss

Inheritance diagram of LabelSmoothingLoss

Inheritance diagram for LabelSmoothingLoss

class kaira.losses.text.LabelSmoothingLoss(smoothing=0.1, classes=0, dim=-1)[source]

Bases: BaseLoss

Label Smoothing Loss Module.

This module implements label smoothing to prevent overconfidence.

Methods

__init__

Initialize the LabelSmoothingLoss module.

forward

Forward pass through the LabelSmoothingLoss module.

__init__(smoothing=0.1, classes=0, dim=-1)[source]

Initialize the LabelSmoothingLoss module.

Parameters:
  • smoothing (float) – Smoothing factor. Default is 0.1.

  • classes (int) – Number of classes. Default is 0.

  • dim (int) – Dimension to reduce. Default is -1.

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

Forward pass through the LabelSmoothingLoss module.

Parameters:
Returns:

The label smoothing loss.

Return type:

torch.Tensor