class_docstr: Triplet loss function.
class_docstr_tok: ["Triplet","loss","function","."]
code: def forward(self, inputs):
      xp = backend.get_array_module(*inputs)
  
      anchor, positive, negative = inputs
  
      dist = (
          xp.sum(
              (anchor - positive) ** 2 - (anchor - negative) ** 2,
              axis=1,
          )
          + self.margin
      )
      self.dist_hinge = xp.maximum(dist, 0)
      if self.reduce == "mean":
          N = anchor.shape[0]
          loss = xp.sum(self.dist_hinge) / N
      else:
          loss = self.dist_hinge
  
      self.retain_inputs((0, 1, 2))
      return (xp.array(loss, dtype=anchor.dtype),)
  
file_path: chainer/chainer/functions/loss/triplet.py
imports: import chainer
  from chainer import backend
  from chainer import function_node
  from chainer.utils import type_check
label_desc: Use image node_id 3 for calling the Triplet obj's underlying member method code with example usage: obj.forward(inputs) and returns: xp