code: def _get_soft_hard_loss(
      self,
      logits: Tuple[torch.Tensor, torch.Tensor, torch.Tensor],
      targets: Tuple[
          torch.Tensor,
          torch.Tensor,
          torch.Tensor,
          torch.Tensor,
          torch.Tensor,
          torch.Tensor,
      ],
  ):
      start_pos_logits, end_pos_logits, has_answer_logits, _, _ = logits
      (
          start_pos_target,
          end_pos_target,
          has_answer_target,
          start_pos_target_logits,
          end_pos_target_logits,
          has_answer_target_logits,
      ) = targets
      num_answers = start_pos_target.size()[-1]
  
      # Start and end position losses
      start_soft_loss, start_hard_loss = self.loss_fn(
          start_pos_logits.repeat((num_answers, 1)),
          (
              start_pos_target.transpose(1, 0).flatten(),
              None,
              start_pos_target_logits.repeat((num_answers, 1)),
          ),
          reduce=False,
          combine_loss=False,
      )
      end_soft_loss, end_hard_loss = self.loss_fn(
          end_pos_logits.repeat((num_answers, 1)),
          (
              end_pos_target.transpose(1, 0).flatten(),
              None,
              end_pos_target_logits.repeat((num_answers, 1)),
          ),
          reduce=False,
          combine_loss=False,
      )
  
      # Sum up along sequence length dimension.
      # Example for KL-divergence: we need to sum up p_i * log(q_i) over i.
      start_soft_loss = torch.sum(start_soft_loss, dim=1)
      end_soft_loss = torch.sum(end_soft_loss, dim=1)
  
      # Weighted sum of soft and hard loss of start and end positions.
      start_loss = self._weighted_loss(start_soft_loss, start_hard_loss)
      end_loss = self._weighted_loss(end_soft_loss, end_hard_loss)
      loss = (start_loss + end_loss).mean()
  
      if not self.ignore_impossible:
          has_answer_mask = (
              has_answer_target.repeat((num_answers,)) == self.true_idx
          ).float()
          position_loss = (
              has_answer_mask * (start_loss + end_loss)
          ).mean()
  
          has_answer_soft_loss, has_answer_hard_loss = self.loss_fn(
              has_answer_logits,
              (has_answer_target, None, has_answer_target_logits),
              reduce=False,
              combine_loss=False,
          )
          has_answer_loss = self._weighted_loss(
              has_answer_soft_loss.mean(), has_answer_hard_loss.mean()
          )
          loss = (
              self.has_answer_loss_weight * has_answer_loss
              + self.pos_loss_weight * position_loss
          )
  
      return loss
  
file_path: pytext/pytext/models/output_layers/squad_output_layer.py
imports: from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
  import torch
  import torch.nn.functional
  from pytext.config.component import create_loss
  from pytext.fields import FieldMeta
  from pytext.loss import BinaryFocalLoss, CrossEntropyLoss, FocalLoss, KLDivergenceCELoss, Loss
  from pytext.models.output_layers import OutputLayerBase
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 7 for calling the SquadOutputLayer obj's underlying member method code with example usage: obj._get_soft_hard_loss(logits, targets) and returns: loss