docstr: Test the soft target cross entropy loss.
docstr_tok: ["Test","the","soft","target","cross","entropy","loss","."]
code: def test_soft_target_cross_entropy_loss(self):
      """
      Test the soft target cross entropy loss.
      """
      for batch_size, num_class, use_1D_target in itertools.product(
          (1, 8), (2, 10), (True, False)
      ):
          loss = SoftTargetCrossEntropyLoss()
  
          # Test forwarding.
          for (
              input_tensor,
              target_tensor,
          ) in TestSoftTargetCrossEntropyLoss._get_inputs(
              batch_size=batch_size,
              num_class=num_class,
              use_1D_target=use_1D_target,
          ):
              output_tensor = loss(input_tensor, target_tensor)
              output_shape = output_tensor.shape
  
              self.assertEqual(
                  output_shape,
                  torch.Size([]),
                  "Output shape {} is different from expected.".format(
                      output_shape
                  ),
              )
  
              # If target is normalized, output_tensor must match direct eval
              if target_tensor.ndim == 1 or all(
                  target_tensor.sum(dim=-1) == 1
              ):
                  _target_tensor = target_tensor
                  if target_tensor.ndim == 1:
                      _target_tensor = torch.nn.functional.one_hot(
                          target_tensor, num_class
                      )
  
                  _output_tensor = torch.sum(
                      -_target_tensor
                      * F.log_softmax(input_tensor, dim=-1),
                      dim=-1,
                  ).mean()
  
                  self.assertTrue(
                      abs(_output_tensor - output_tensor) < 1e-6
                  )
  
file_path: pytorchvideo/tests/test_losses_soft_target_cross_entropy.py
imports: import itertools
  import unittest
  import torch
  import torch.nn.functional
  from pytorchvideo.losses.soft_target_cross_entropy import SoftTargetCrossEntropyLoss
label_desc: Use image node_id 2 for calling the TestSoftTargetCrossEntropyLoss obj's underlying member method code with example usage: obj.test_soft_target_cross_entropy_loss() without return types