parameters: (labels, embeddings_anchor, embeddings_positive,
                       margin=1.0)
return_statement: return math_ops.reduce_mean(
        math_ops.cast(labels, distances.dtype) * math_ops.square(distances) +
        (1. - math_ops.cast(labels, distances.dtype)) *
        math_ops.square(math_ops.maximum(margin - distances, 0.)),
        name='contrastive_loss')
docstring: Computes the contrastive loss.
  
    This loss encourages the embedding to be close to each other for
      the samples of the same label and the embedding to be far apart at least
      by the margin constant for the samples of different labels.
    See: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf
  
    Args:
      labels: 1-D tf.int32 `Tensor` with shape [batch_size] of
        binary labels indicating positive vs negative pair.
      embeddings_anchor: 2-D float `Tensor` of embedding vectors for the anchor
        images. Embeddings should be l2 normalized.
      embeddings_positive: 2-D float `Tensor` of embedding vectors for the
        positive images. Embeddings should be l2 normalized.
      margin: margin term in the loss definition.
  
    Returns:
      contrastive_loss: tf.float32 scalar.
docstring_summary: Computes the contrastive loss.
docstring_tokens: Computes the contrastive loss .
function: def contrastive_loss(labels, embeddings_anchor, embeddings_positive,
                       margin=1.0):
    """Computes the contrastive loss.
  
    This loss encourages the embedding to be close to each other for
      the samples of the same label and the embedding to be far apart at least
      by the margin constant for the samples of different labels.
    See: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf
  
    Args:
      labels: 1-D tf.int32 `Tensor` with shape [batch_size] of
        binary labels indicating positive vs negative pair.
      embeddings_anchor: 2-D float `Tensor` of embedding vectors for the anchor
        images. Embeddings should be l2 normalized.
      embeddings_positive: 2-D float `Tensor` of embedding vectors for the
        positive images. Embeddings should be l2 normalized.
      margin: margin term in the loss definition.
  
    Returns:
      contrastive_loss: tf.float32 scalar.
    """
    # Get per pair distances
    distances = math_ops.sqrt(
        math_ops.reduce_sum(
            math_ops.squared_difference(embeddings_anchor, embeddings_positive),
            1))
  
    # Add contrastive loss for the siamese network.
    #   label here is {0,1} for neg, pos.
    return math_ops.reduce_mean(
        math_ops.cast(labels, distances.dtype) * math_ops.square(distances) +
        (1. - math_ops.cast(labels, distances.dtype)) *
        math_ops.square(math_ops.maximum(margin - distances, 0.)),
        name='contrastive_loss')
function_tokens: def contrastive_loss ( labels , embeddings_anchor , embeddings_positive , margin = 1.0 ) : # Get per pair distances distances = math_ops . sqrt ( math_ops . reduce_sum ( math_ops . squared_difference ( embeddings_anchor , embeddings_positive ) , 1 ) ) # Add contrastive loss for the siamese network. #   label here is {0,1} for neg, pos. return math_ops . reduce_mean ( math_ops . cast ( labels , distances . dtype ) * math_ops . square ( distances ) + ( 1. - math_ops . cast ( labels , distances . dtype ) ) * math_ops . square ( math_ops . maximum ( margin - distances , 0. ) ) , name = 'contrastive_loss' )