class_docstr: Neural module which implements loss for SGD model.
class_docstr_tok: ["Neural","module","which","implements","loss","for","SGD","model","."]
code: def forward(
      self,
      logit_intent_status,
      intent_status,
      logit_req_slot_status,
      requested_slot_status,
      logit_cat_slot_status,
      categorical_slot_status,
      logit_cat_slot_value_status,
      categorical_slot_value_status,
      logit_noncat_slot_status,
      noncategorical_slot_status,
      logit_spans,
      noncategorical_slot_value_start,
      noncategorical_slot_value_end,
      task_mask,
  ):
      # Intent loss
  
      old_logit_intent_status = logit_intent_status
      logit_intent_status, intent_status = self._helper(
          logit_intent_status, intent_status, task_mask[:, 0]
      )
      if len(intent_status) == 0:
          intent_loss = torch.clamp(
              torch.max(old_logit_intent_status.view(-1)), 0, 0
          )
      else:
          intent_loss = self._cross_entropy_bin(
              logit_intent_status.squeeze(dim=-1), intent_status
          )
  
      old_logit_req_slot_status = logit_req_slot_status
      logit_req_slot_status, requested_slot_status = self._helper(
          logit_req_slot_status, requested_slot_status, task_mask[:, 1]
      )
      if len(requested_slot_status) == 0:
          requested_slot_loss = torch.clamp(
              torch.max(old_logit_req_slot_status.view(-1)), 0, 0
          )
      else:
          requested_slot_loss = self._cross_entropy_bin(
              logit_req_slot_status.squeeze(dim=-1),
              requested_slot_status,
          )
  
      old_logit_cat_slot_status = logit_cat_slot_status
      logit_cat_slot_status, categorical_slot_status = self._helper(
          logit_cat_slot_status,
          categorical_slot_status,
          task_mask[:, 2],
      )
      if len(categorical_slot_status) == 0:
          cat_slot_status_loss = torch.clamp(
              torch.max(old_logit_cat_slot_status.view(-1)), 0, 0
          )
      else:
          cat_slot_status_loss = self._cross_entropy(
              logit_cat_slot_status,
              categorical_slot_status,
          )
      old_logit_cat_slot_value_status = logit_cat_slot_value_status
      (
          logit_cat_slot_value_status,
          categorical_slot_value_status,
      ) = self._helper(
          logit_cat_slot_value_status,
          categorical_slot_value_status,
          task_mask[:, 3],
      )
      if len(categorical_slot_value_status) == 0:
          cat_slot_value_status_loss = torch.clamp(
              torch.max(old_logit_cat_slot_value_status.view(-1)), 0, 0
          )
      else:
          cat_slot_value_status_loss = self._cross_entropy_bin(
              logit_cat_slot_value_status.squeeze(dim=-1),
              categorical_slot_value_status,
          )
  
      old_logit_noncat_slot_status = logit_noncat_slot_status
      (
          logit_noncat_slot_status,
          noncategorical_slot_status,
      ) = self._helper(
          logit_noncat_slot_status,
          noncategorical_slot_status,
          task_mask[:, 4],
      )
      if len(noncategorical_slot_status) == 0:
          noncat_slot_status_loss = torch.clamp(
              torch.max(old_logit_noncat_slot_status.view(-1)), 0, 0
          )
      else:
          noncat_slot_status_loss = self._cross_entropy(
              logit_noncat_slot_status,
              noncategorical_slot_status,
          )
  
      logit_noncat_slot_start, logit_noncat_slot_end = torch.unbind(
          logit_spans, dim=-1
      )
  
      _, max_num_tokens = logit_noncat_slot_start.size()
      old_logit_noncat_slot_start = logit_noncat_slot_start
      (
          logit_noncat_slot_start,
          noncategorical_slot_value_start,
      ) = self._helper(
          logit_noncat_slot_start,
          noncategorical_slot_value_start,
          task_mask[:, 5],
      )
      if len(noncategorical_slot_value_start) == 0:
          span_start_loss = torch.clamp(
              torch.max(old_logit_noncat_slot_start.view(-1)), 0, 0
          )
      else:
          span_start_loss = self._cross_entropy(
              logit_noncat_slot_start, noncategorical_slot_value_start
          )
  
      old_logit_noncat_slot_end = logit_noncat_slot_end
      (
          logit_noncat_slot_end,
          noncategorical_slot_value_end,
      ) = self._helper(
          logit_noncat_slot_end,
          noncategorical_slot_value_end,
          task_mask[:, 5],
      )
      if len(noncategorical_slot_value_end) == 0:
          span_end_loss = torch.clamp(
              torch.max(old_logit_noncat_slot_end.view(-1)), 0, 0
          )
      else:
          span_end_loss = self._cross_entropy(
              logit_noncat_slot_end, noncategorical_slot_value_end
          )
  
      losses = {
          "intent_loss": intent_loss,
          "requested_slot_loss": requested_slot_loss,
          "cat_slot_status_loss": cat_slot_status_loss,
          "cat_slot_value_status_loss": cat_slot_value_status_loss,
          "noncat_slot_status_loss": noncat_slot_status_loss,
          "span_start_loss": span_start_loss,
          "span_end_loss": span_end_loss,
      }
  
      total_loss = sum(losses.values())
      if self.reduction == "mean":
          total_loss = total_loss / len(losses)
      else:
          batch_size = logit_intent_status.shape[0]
          total_loss = total_loss / batch_size
      return total_loss
  
file_path: NeMo/nemo/collections/nlp/losses/sgd_loss.py
imports: import torch
  from nemo.core.classes import Loss, Typing, typecheck
  from nemo.core.neural_types import ChannelType, LabelsType, LogitsType, LossType, NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling the SGDDialogueStateLoss obj's underlying member method code with example usage: obj.forward(logit_intent_status, intent_status, logit_req_slot_status, requested_slot_status, logit_cat_slot_status, categorical_slot_status, logit_cat_slot_value_status, categorical_slot_value_status, logit_noncat_slot_status, noncategorical_slot_status, logit_spans, noncategorical_slot_value_start, noncategorical_slot_value_end, task_mask) and returns: total_loss