import tensorflow as tf

    signed_logits_difference = labels_difference * logits_difference
    raw_loss = losses_utils.weighted_surrogate_loss(
        labels=tf.ones_like(signed_logits_difference),
        logits=signed_logits_difference,
        surrogate_type=surrogate_type)
    weighted_loss = weights_product * raw_loss

    # Zero out entries of the loss where labels_difference zero (so loss is only
    # computed on pairs with different labels).
    loss = tf.reduce_mean(tf.abs(labels_difference) * weighted_loss, 0) * 0.5
    loss = tf.reshape(loss, original_shape)
    return loss, {}


def recall_at_precision_loss(labels,
                             logits,
                             target_precision,
                             weights=1.0,
                             dual_rate_factor=0.1,
                             label_priors=None,
