code: def cosine_embedding_loss(
      input1,
      input2,
      target,
      margin=0.0,
      size_average=None,
      reduce=None,
      reduction="mean",
  ):
      def norm(input, axis):
          return ivy.sqrt(ivy.sum(ivy.square(input), axis=axis))
  
      def cosine_similarity(x1, x2):
          axis = None
          if len(x1.shape) == len(x2.shape) and len(x2.shape) == 2:
              axis = 1
          input1_norm = norm(x1, axis=axis)
          input2_norm = norm(x2, axis=axis)
          norm_mm = input1_norm * input2_norm
          norm_mm, eps = torch_frontend.promote_types_of_torch_inputs(
              norm_mm, 1e-08
          )
          return ivy.sum(x1 * x2, axis=axis) / ivy.maximum(norm_mm, eps)
  
      def calculate_loss(x1, x2, target):
          cos = cosine_similarity(x1, x2)
          if target == ivy.array(1.0):
              loss = 1.0 - cos
          elif target == ivy.array(-1.0):
              loss = ivy.maximum(
                  ivy.array(0.0), cos - ivy.array(margin)
              )
          else:
              _, zero = torch_frontend.promote_types_of_torch_inputs(
                  input1, ivy.array(0.0)
              )
              return zero
  
          return loss
  
      ivy.utils.assertions.check_true(
          target.ndim + 1 == input1.ndim
          and target.ndim + 1 == input2.ndim,
          f"{target.ndim}D target tensor expects {target.ndim + 1}D input tensors, but "
          f"found inputs with sizes {list(input1.shape)} and {list(input2.shape)}.",
      )
  
      ivy.utils.assertions.check_true(
          target.ndim < 2,
          "0D or 1D target tensor expected, multi-target not supported",
      )
  
      ivy.utils.assertions.check_shape(input1, input2)
  
      if target.ndim == 1:
          ivy.utils.assertions.check_true(
              target.shape[0] == input1.shape[0],
              f"The size of target tensor ({target.shape[0]}) must match the size of"
              f" input tensor ({input1.shape[0]}) at non-singleton dimension 0 ",
          )
  
      if target.ndim == 0:
          loss = calculate_loss(input1, input2, target)
      else:
          loss = ivy.array(
              [
                  calculate_loss(input1[i], input2[i], target[i])
                  for i in range(input1.shape[0])
              ]
          )
  
      reduction = _get_reduction(reduction, size_average, reduce)
      loss = reduction(loss)
      return loss
  
imports: import ivy
  import ivy.functional.frontends.torch
  from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
label_desc: Use image node_id 8 for calling a global function with example usage: cosine_embedding_loss(input1, input2, target, margin, size_average, reduce, reduction) and returns: loss, ivy, unknown, loss, zero