code: def forward(self, model, sample, reduce=True):
      net_output = model(**sample["net_input"])
      lprobs = model.get_normalized_probs(net_output, log_probs=True)
      assert (
          "weights" in sample
      ), "Need to specify weights for examples."
      weights = sample["weights"].unsqueeze(1).unsqueeze(2)
      lprobs = lprobs * weights
  
      lprobs = lprobs.view(-1, lprobs.size(-1))
      target = model.get_targets(sample, net_output).view(-1, 1)
      non_pad_mask = target.ne(self.padding_idx)
      nll_loss = -lprobs.gather(dim=-1, index=target)[non_pad_mask]
      smooth_loss = -lprobs.sum(dim=-1, keepdim=True)[non_pad_mask]
      if reduce:
          nll_loss = nll_loss.sum()
          smooth_loss = smooth_loss.sum()
      eps_i = self.eps / lprobs.size(-1)
      loss = (1.0 - self.eps) * nll_loss + eps_i * smooth_loss
  
      sample_size = (
          sample["target"].size(0)
          if self.args.sentence_avg
          else sample["ntokens"]
      )
      logging_output = {
          "loss": utils.item(loss.data) if reduce else loss.data,
          "nll_loss": utils.item(nll_loss.data)
          if reduce
          else loss.data,
          "ntokens": sample["ntokens"],
          "nsentences": sample["target"].size(0),
          "sample_size": sample_size,
      }
      return loss, sample_size, logging_output
  
file_path: translate/pytorch_translate/weighted_criterions.py
imports: from fairseq import utils
  from fairseq.criterions import LegacyFairseqCriterion, register_criterion
  from fairseq.criterions.label_smoothed_cross_entropy import LabelSmoothedCrossEntropyCriterion
label_desc: Use image node_id 3 for calling the WeightedLabelSmoothedCrossEntropyCriterion obj's underlying member method code with example usage: obj.forward(model, sample, reduce) and returns: loss,  sample_size,  logging_output