class_docstr: This class implements triplet loss. Given a triplet of (anchor, positive, negative),
  the loss minimizes the distance between anchor and positive while it maximizes the distance
  between anchor and negative. It compute the following loss function:
  
  loss = max(||anchor - positive|| - ||anchor - negative|| + margin, 0).
  
  Margin is an important hyperparameter and needs to be tuned respectively.
  
  For further details, see: https://en.wikipedia.org/wiki/Triplet_loss
  
  :param model: SentenceTransformerModel
  :param distance_metric: Function to compute distance between two embeddings. The class TripletDistanceMetric contains common distance metrices that can be used.
  :param triplet_margin: The negative should be at least this much further away from the anchor than the positive.
  
  Example::
  
      from sentence_transformers import SentenceTransformer,  SentencesDataset, LoggingHandler, losses
      from sentence_transformers.readers import InputExample
  
      model = SentenceTransformer('distilbert-base-nli-mean-tokens')
      train_examples = [InputExample(texts=['Anchor 1', 'Positive 1', 'Negative 1']),
          InputExample(texts=['Anchor 2', 'Positive 2', 'Negative 2'])]
      train_dataset = SentencesDataset(train_examples, model)
      train_dataloader = DataLoader(train_dataset, shuffle=True, batch_size=train_batch_size)
      train_loss = losses.TripletLoss(model=model)
code: def forward(
      self,
      sentence_features: Iterable[Dict[str, Tensor]],
      labels: Tensor,
  ):
      reps = [
          self.model(sentence_feature)["sentence_embedding"]
          for sentence_feature in sentence_features
      ]
  
      rep_anchor, rep_pos, rep_neg = reps
      distance_pos = self.distance_metric(rep_anchor, rep_pos)
      distance_neg = self.distance_metric(rep_anchor, rep_neg)
  
      losses = F.relu(distance_pos - distance_neg + self.triplet_margin)
      return losses.mean()
  
file_path: sentence-transformers/sentence_transformers/losses/TripletLoss.py
imports: from torch import nn, Tensor
  from typing import Iterable, Dict
  import torch.nn.functional
  from enum import Enum
  from ..SentenceTransformer import SentenceTransformer
label_desc: Use image node_id 3 for calling the TripletLoss obj's underlying member method code with example usage: obj.forward(sentence_features, labels) and returns: losses