code: def mrr(scores, candidates, labels):
      """Compute Mean Reciprocal Rank of labels in scores.
  
      Args:
        scores (tf.Tensor): batchsize, max_candidates tensor of scores
        candidates (tf.Tensor): batchsize, max_candidates tensor of candidate ids
        labels (tf.Tensor): batchsize tensor of ground truth labels
      Returns:
        rr (tf.Tensor): batchsize tensor of Reciprocal Rank values
      """
      _, top_score_ids = tf.nn.top_k(scores, k=tf.shape(scores)[-1])
      batch_indices = tf.cumsum(
          tf.ones_like(candidates, dtype=tf.int32),
          axis=0,
          exclusive=True,
      )
      indices = tf.concat(
          [
              tf.expand_dims(batch_indices, axis=-1),
              tf.expand_dims(top_score_ids, -1),
          ],
          -1,
      )
      sorted_candidates = tf.gather_nd(candidates, indices)
      # label_ids = tf.expand_dims(tf.argmax(labels, axis=1), 1)
      label_rank_indices = tf.where(tf.equal(sorted_candidates, labels))
      # +1 because top rank should be 1 not 0
      ranks = label_rank_indices[:, 1] + 1
      rr = 1.0 / tf.cast(ranks, tf.float32)
      return rr
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: mrr(scores, candidates, labels) and returns: rr