code: def test_label_smoothed_cross_entropy_loss_forward(self):
      torch.manual_seed(1)
      np.random.seed(1)
  
      for _ in range(50):
          beta = 0.1
          reduce = np.random.choice([True, False])
          num_classes = np.random.randint(1, 10)
          input_size = np.random.randint(1, 10)
          logits = torch.randn(input_size, num_classes)
          targets = torch.randint(num_classes, (input_size,))
          num_padding_indices = np.random.randint(
              0, int(logits.shape[0] / 2) + 1
          )
          padding_indices = np.random.choice(
              logits.shape[0], num_padding_indices, replace=False
          )
          targets[padding_indices] = -100
  
          # Only testing for None now because unexpected behavior with nll_loss.
          # Look at definition of LabelSmoothedCrossEntropyLoss for more
          # context.
          weight = None
  
          manual_loss = self._compute_loss_manual(
              logits,
              targets,
              weight=weight,
              reduce=reduce,
              beta=beta,
              ignore_index=-100,
          )
          loss_fn = LabelSmoothedCrossEntropyLoss(
              config=LabelSmoothedCrossEntropyLoss.Config(),
              ignore_index=-100,
              weight=weight,
          )
          label_smoothed_loss = loss_fn(logits, targets, reduce=reduce)
  
          diff = np.array(manual_loss) - np.array(label_smoothed_loss)
          error = np.linalg.norm(diff)
          self.assertAlmostEqual(error, 0.0, places=4)
  
          loss_log_config = LabelSmoothedCrossEntropyLoss.Config()
          loss_log_config.source = SourceType.LOG_PROBS
          loss_log_fn = LabelSmoothedCrossEntropyLoss(
              config=loss_log_config, ignore_index=-100, weight=weight
          )
          label_smoothed_log_loss = loss_log_fn(
              torch.nn.functional.log_softmax(logits, dim=-1),
              targets,
              reduce=reduce,
          )
          log_diff = np.array(manual_loss) - np.array(
              label_smoothed_log_loss
          )
          error = np.linalg.norm(log_diff)
          self.assertAlmostEqual(error, 0.0, places=4)
  
file_path: pytext/pytext/loss/tests/label_smoothing_loss_test.py
imports: import caffe2.python.hypothesis_test_util
  import numpy
  import torch
  from pytext.loss.loss import LabelSmoothedCrossEntropyLoss, SourceType
  from scipy.special import logsumexp
label_desc: Use image node_id 1 for calling the LabelSmoothedCrossEntropyLossTest obj's underlying member method code with example usage: obj.test_label_smoothed_cross_entropy_loss_forward() without return types