class_docstr: Computes a cross-entropy loss, normalized by the number of valid (non-pad) tokens.
  Uses an efficient implementation for label smoothing and avoids the obscure SoftmaxOutput op.
class_docstr_tok: ["Computes","a","cross-entropy","loss",",","normalized","by","the","number","of","valid","(","non-pad",")","tokens",".","Uses","an","efficient","implementation","for","label","smoothing","and","avoids","the","obscure","SoftmaxOutput","op","."]
docstr: Computes label-smoothed cross-entropy loss just like sockeye.loss.CrossEntropyLossWithoutSoftmaxOutput()
  Notable details:
  - smoothing with 1/vocab_size, not 1/(vocab_size-1) as in fairseq
  - form taken from https://github.com/dmlc/gluon-nlp/blob/b714eaccc67619d7bdcbd1574d30be87d9c73f0c/src/gluonnlp/loss.py#L4
code: def _smoothed_loss_as_in_mxnet(self, logits, labels):
      """
      Computes label-smoothed cross-entropy loss just like sockeye.loss.CrossEntropyLossWithoutSoftmaxOutput()
      Notable details:
      - smoothing with 1/vocab_size, not 1/(vocab_size-1) as in fairseq
      - form taken from https://github.com/dmlc/gluon-nlp/blob/b714eaccc67619d7bdcbd1574d30be87d9c73f0c/src/gluonnlp/loss.py#L4
      """
      pred = pt.log_softmax(logits, dim=-1)
      nll = -pred.gather(
          dim=-1, index=labels.unsqueeze(-1).long()
      ).squeeze(-1)
      all_scores = pred.sum(dim=-1)
      # (batch, len,)
      valid_mask = labels.not_equal(self.ignore_label)
      pad_mask = ~valid_mask
      nll.masked_fill_(pad_mask, 0.0)
      all_scores.masked_fill_(pad_mask, 0.0)
  
      nll = (1 - self._alpha) * nll - self._alpha / logits.size(
          -1
      ) * all_scores
      num_valid = valid_mask.sum()
      ce = nll.sum() * self.weight / num_valid
      return ce
  
imports: import logging
  import math
  from abc import ABC, abstractmethod
  from typing import Any, Dict, Optional, Tuple
  import torch
  import numpy
  from .None import constants
  from .None import utils
label_desc: Use image node_id 2 for calling the CrossEntropyLoss obj's underlying member method code with example usage: obj._smoothed_loss_as_in_mxnet(logits, labels) and returns: ce