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
docstr: :param model: SentenceTransformerModel
  :param positive_margin: Positive margin, cos(anchor, positive) should be > positive_margin
  :param negative_margin: Negative margin, cos(anchor, negative) should be < negative_margin
  :param use_mini_batched_version: As large batch sizes require a lot of memory, we can use a mini-batched version. We break down the large batch with 500 examples to smaller batches with fewer examples.
  :param mini_batch_size: Size for the mini-batches. Should be a devisor for the batch size in your data loader.
code: def __init__(
      self,
      model,
      positive_margin: float = 0.8,
      negative_margin: float = 0.3,
      use_mini_batched_version: bool = True,
      mini_batch_size: int = 50,
  ):
      """
      :param model: SentenceTransformerModel
      :param positive_margin: Positive margin, cos(anchor, positive) should be > positive_margin
      :param negative_margin: Negative margin, cos(anchor, negative) should be < negative_margin
      :param use_mini_batched_version: As large batch sizes require a lot of memory, we can use a mini-batched version. We break down the large batch with 500 examples to smaller batches with fewer examples.
      :param mini_batch_size: Size for the mini-batches. Should be a devisor for the batch size in your data loader.
      """
      super(MegaBatchMarginLoss, self).__init__()
      self.model = model
      self.positive_margin = positive_margin
      self.negative_margin = negative_margin
      self.mini_batch_size = mini_batch_size
      self.forward = (
          self.forward_mini_batched
          if use_mini_batched_version
          else self.forward_non_mini_batched
      )
  
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 1 to create a new MegaBatchMarginLoss object from inherited base classes: nn with example: obj = MegaBatchMarginLoss(model, positive_margin, negative_margin, use_mini_batched_version, mini_batch_size)