class_docstr: Args:
      margin: The desired difference between the anchor-positive distance and the
              anchor-negative distance.
      swap: Use the positive-negative distance instead of anchor-negative distance,
            if it violates the margin more.
      smooth_loss: Use the log-exp version of the triplet loss
code: def compute_loss(
      self, embeddings, labels, indices_tuple, ref_emb, ref_labels
  ):
      c_f.labels_or_indices_tuple_required(labels, indices_tuple)
      indices_tuple = lmu.convert_to_triplets(
          indices_tuple,
          labels,
          ref_labels,
          t_per_anchor=self.triplets_per_anchor,
      )
      anchor_idx, positive_idx, negative_idx = indices_tuple
      if len(anchor_idx) == 0:
          return self.zero_losses()
      mat = self.distance(embeddings, ref_emb)
      ap_dists = mat[anchor_idx, positive_idx]
      an_dists = mat[anchor_idx, negative_idx]
      if self.swap:
          pn_dists = mat[positive_idx, negative_idx]
          an_dists = self.distance.smallest_dist(an_dists, pn_dists)
  
      current_margins = self.distance.margin(ap_dists, an_dists)
      violation = current_margins + self.margin
      if self.smooth_loss:
          loss = torch.nn.functional.softplus(violation)
      else:
          loss = torch.nn.functional.relu(violation)
  
      return {
          "loss": {
              "losses": loss,
              "indices": indices_tuple,
              "reduction_type": "triplet",
          }
      }
  
file_path: pytorch-metric-learning/src/pytorch_metric_learning/losses/triplet_margin_loss.py
imports: import torch
  from ..reducers import AvgNonZeroReducer
  from ..utils import common_functions
  from ..utils import loss_and_miner_utils
  from .base_metric_loss_function import BaseMetricLossFunction
label_desc: Use image node_id 2 for calling the TripletMarginLoss obj's underlying member method code with example usage: obj.compute_loss(embeddings, labels, indices_tuple, ref_emb, ref_labels) and returns: dict, self