class_docstr: Loss function inspired from ParaNMT paper:
  https://www.aclweb.org/anthology/P18-1042/
  
  Given a large batch (like 500 or more examples) of (anchor_i, positive_i) pairs,
  find for each pair in the batch the hardest negative, i.e. find j != i such that cos_sim(anchor_i, positive_j)
  is maximal. Then create from this a triplet (anchor_i, positive_i, positive_j) where positive_j
  serves as the negative for this triplet.
  
  Train than as with the triplet loss
code: def forward_non_mini_batched(
      self,
      sentence_features: Iterable[Dict[str, Tensor]],
      labels: Tensor,
  ):
      reps = [
          self.model(sentence_feature)["sentence_embedding"]
          for sentence_feature in sentence_features
      ]
      embeddings_a, embeddings_b = reps
  
      cos_scores = util.pytorch_cos_sim(embeddings_a, embeddings_b)
      positive_scores = torch.diagonal(cos_scores)
      negative_scores = cos_scores - (
          2 * torch.eye(*cos_scores.shape, device=cos_scores.device)
      )  # Remove positive scores along the diagonal
      negatives_max, _ = torch.max(negative_scores, dim=1)
      losses = F.relu(self.positive_margin - positive_scores) + F.relu(
          negatives_max - self.negative_margin
      )
      return losses.mean()
  
file_path: sentence-transformers/sentence_transformers/losses/MegaBatchMarginLoss.py
imports: from ..None import util
  import torch
  from torch import nn, Tensor
  from typing import Iterable, Dict
  import torch.nn.functional
label_desc: Use image node_id 3 for calling the MegaBatchMarginLoss obj's underlying member method code with example usage: obj.forward_non_mini_batched(sentence_features, labels) and returns: losses