code: def _get_hard_loss(
      self,
      logits: Tuple[torch.Tensor, torch.Tensor],
      targets: Tuple[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 = targets
      num_answers = start_pos_target.size()[-1]
  
      if num_answers == 0 and not self.use_zero_answer:
          start_loss = torch.tensor(0.0, dtype=torch.float).type_as(
              end_pos_logits
          )
          end_loss = torch.tensor(0.0, dtype=torch.float).type_as(
              end_pos_logits
          )
      else:
          start_loss = self.loss_fn(
              start_pos_logits.repeat((num_answers, 1)),
              start_pos_target.transpose(1, 0).flatten(),
              reduce=False,
          )
          end_loss = self.loss_fn(
              end_pos_logits.repeat((num_answers, 1)),
              end_pos_target.transpose(1, 0).flatten(),
              reduce=False,
          )
      loss = (start_loss + end_loss).mean()
      if not self.ignore_impossible:
          if self.use_zero_answer:
              position_loss = (start_loss + end_loss).mean()
          else:
              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_loss = self.loss_fn(
              has_answer_logits, has_answer_target
          )
          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 6 for calling the SquadOutputLayer obj's underlying member method code with example usage: obj._get_hard_loss(logits, targets) and returns: loss