class_docstr: Triplet loss function.
class_docstr_tok: ["Triplet","loss","function","."]
code: def backward(self, indexes, grad_outputs):
      anchor, positive, negative = self.get_retained_inputs()
  
      N = anchor.shape[0]
      x_dim = anchor.shape[1]
  
      xp = backend.get_array_module(anchor)
      tmp = xp.repeat(self.dist_hinge[:, None], x_dim, axis=1)
      mask = xp.array(tmp > 0, dtype=anchor.dtype)
  
      (gy,) = grad_outputs
      if self.reduce == "mean":
          g = gy / N
      else:
          g = gy[:, None]
  
      tmp = 2 * chainer.functions.broadcast_to(g, mask.shape) * mask
  
      ret = []
      if 0 in indexes:
          ret.append(tmp * (negative - positive))
      if 1 in indexes:
          ret.append(tmp * (positive - anchor))
      if 2 in indexes:
          ret.append(tmp * (anchor - negative))
  
      return ret
  
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 4 for calling the Triplet obj's underlying member method code with example usage: obj.backward(indexes, grad_outputs) and returns: ret