docstr: for N examples and C classes
  - output: N x C these are raw outputs (without softmax/sigmoid)
  - target: N x C or N corresponding targets
  
  Target elements set to ignore_index contribute 0 loss.
  
  Samples where all entries are ignore_index do not contribute to the loss
  reduction.
code: def forward(self, output, target):
      """for N examples and C classes
      - output: N x C these are raw outputs (without softmax/sigmoid)
      - target: N x C or N corresponding targets
  
      Target elements set to ignore_index contribute 0 loss.
  
      Samples where all entries are ignore_index do not contribute to the loss
      reduction.
      """
      # check if targets are inputted as class integers
      if target.ndim == 1:
          assert (
              output.shape[0] == target.shape[0]
          ), "SoftTargetCrossEntropyLoss requires output and target to have same batch size"
          target = convert_to_one_hot(
              target.view(-1, 1), output.shape[1]
          )
      assert output.shape == target.shape, (
          "SoftTargetCrossEntropyLoss requires output and target to be same "
          f"shape: {output.shape} != {target.shape}"
      )
      valid_mask = target != self._ignore_index
      valid_targets = target.float() * valid_mask.float()
      if self._normalize_targets:
          valid_targets /= self._eps + valid_targets.sum(
              dim=1, keepdim=True
          )
      per_sample_per_target_loss = -valid_targets * F.log_softmax(
          output, -1
      )
      per_sample_loss = torch.sum(per_sample_per_target_loss, -1)
      # perform reduction
      if self._reduction == "mean":
          # normalize based on the number of samples with > 0 non-ignored targets
          loss = per_sample_loss.sum() / torch.sum(
              (torch.sum(valid_mask, -1) > 0)
          ).clamp(min=1)
      elif self._reduction == "none":
          loss = per_sample_loss
  
      return loss
  
file_path: ClassyVision/classy_vision/losses/soft_target_cross_entropy_loss.py
imports: from typing import Any, Dict
  import torch
  import torch.nn.functional
  from classy_vision.generic.util import convert_to_one_hot
  from classy_vision.losses import ClassyLoss, register_loss
label_desc: Use image node_id 3 for calling the SoftTargetCrossEntropyLoss obj's underlying member method code with example usage: obj.forward(output, target) and returns: loss