code: def get_position_preds(
      self,
      start_pos_logits: torch.Tensor,
      end_pos_logits: torch.Tensor,
      max_span_length: int,
      best_n: int = 1,
  ):
      # the following is to enforce end_pos > start_pos.  We create a matrix
      # of start_position X end_position, fill it with the sum logits,
      # then mask it to be upper-triangular
      # e.g. start_pos_logits = [1, 3, 0, 5, 2]
      #      end_pos_logits = [2, 4, 6, 3, 5]
      # The max indices should be (3,4) with values (5,5).  (5,6) would have a
      # higher score, but end_pos would be before start, so it's not feasible
      #
      # To calculate this, first create a matrix with i,j entry containing
      # start_pos_logits[i] + end_pos_logits[j]
      #                   = [[3, 5, 7, 4, 6],
      #                     [5, 7, 9, 6, 8],
      #                     [2, 4, 6, 3, 5],
      #                     [7, 9, 11, 8, 10],
      #                     [4, 6, 8, 5, 7]]
      # Then mask it to be upper-triagular:
      #  logit_sum_matrix = [[3, 5, 7, 4, 6],
      #                     [0, 7, 9, 6, 8],
      #                     [0, 0, 6, 3, 5],
      #                     [0, 0, 0, 8, 10],
      #                     [0, 0, 0, 0, 7]]
      # Then we use argmax to retrieve the indices of the max value.
      size = start_pos_logits.size() + (start_pos_logits.size()[-1],)
      start_pos_logits = (
          start_pos_logits.unsqueeze(-1).expand(size) + 10
      )
      end_pos_logits = (
          end_pos_logits.unsqueeze(-1).expand(size).transpose(-2, -1)
          + 10
      )
      logit_sum_matrix = (start_pos_logits + end_pos_logits).triu()
      for i in range(logit_sum_matrix.size()[1]):
          logit_sum_matrix[:, i, i + max_span_length :] = 0
  
      # Method 1, can't guarantee non overlapping of spans
      _, ids_flatten = torch.topk(
          logit_sum_matrix.flatten(start_dim=-2, end_dim=-1),
          best_n,
          dim=-1,
      )  # ids_flatten shape of (bs, best_n)
      ids = ids_flatten.flatten()  # (bs*best_n,)
      start_position = ids // logit_sum_matrix.shape[-1]  # (bs*best_n,)
      end_position = ids.fmod(
          logit_sum_matrix.shape[-1]
      )  # (bs*best_n,)
      start_position = start_position.reshape(
          -1, best_n
      )  # (bs, best_n)
      end_position = end_position.reshape(-1, best_n)  # (bs, best_n)
  
      return start_position, end_position
  
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 3 for calling the SquadOutputLayer obj's underlying member method code with example usage: obj.get_position_preds(start_pos_logits, end_pos_logits, max_span_length, best_n) and returns: start_position,  end_position