code: def forward(self, x: torch.Tensor, target: torch.Tensor):
      assert x.shape[1] == self.size
      true_dist = x.clone()
      true_dist.fill_(self.smoothing / (self.size - 2))
      true_dist.scatter_(1, target.unsqueeze(1), self.confidence)
      true_dist[:, self.padding_idx] = 0
      mask = torch.nonzero(target == self.padding_idx, as_tuple=False)
      if mask.dim() > 0:
          true_dist.index_fill_(0, mask.squeeze(), 0.0)
      self.true_dist = true_dist
      return self.loss(x, true_dist.detach())
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/transformers/label_smoothing_loss.py
imports: import matplotlib.pyplot
  import numpy
  import torch
  import torch.nn
  from labml_helpers.module import Module
label_desc: Use image node_id 2 for calling the LabelSmoothingLoss obj's underlying member method code with example usage: obj.forward(x, target) and returns: self