code: def hits_at_k(scores, candidates, labels, k=10):
      """Compute hits@k.
  
      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
        k: values of k to evaluate hits@k
      Returns:
        rr (tf.Tensor): batchsize tensor of Reciprocal Rank values
      """
      _, top_score_ids = tf.nn.top_k(scores, k=k)
      batch_indices = tf.cumsum(
          tf.ones_like(top_score_ids, 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)
      hits = tf.reduce_max(
          tf.cast(tf.equal(sorted_candidates, labels), tf.float32), 1
      )
      return hits
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
label_desc: Use image node_id 2 for calling a global function with example usage: hits_at_k(scores, candidates, labels, k) and returns: hits