code: def hard_negative_mining(
      loss: Tensor, labels: Tensor, neg_pos_ratio: int, *args, **kwargs
  ) -> Tensor:
      """
      This function is used to suppress the presence of a large number of negative predictions. For any example/image,
      it keeps all the positive predictions and cut the number of negative predictions to make sure the ratio
      between the negative examples and positive examples is no more than the given ratio for an image.
      Args:
          loss (Tensor): the loss for each example and has shape (N, num_priors).
          labels (Tensor): the labels and has shape (N, num_priors).
          neg_pos_ratio (int):  the ratio between the negative examples and positive examples. Usually, it is set as 3.
  
      """
      pos_mask = labels > 0
      num_pos = pos_mask.long().sum(dim=1, keepdim=True)
      num_neg = num_pos * neg_pos_ratio
  
      loss[pos_mask] = -math.inf
      _, indexes = loss.sort(dim=1, descending=True)
      _, orders = indexes.sort(dim=1)
      neg_mask = orders < num_neg
      return pos_mask | neg_mask
  
imports: import math
  from typing import Optional, Tuple
  import torch
  from torch import Tensor
label_desc: Use image node_id 3 for calling a global function with example usage: hard_negative_mining(loss, labels, neg_pos_ratio) and returns: unknown