code: def eval_metric(metric_fn, **kwargs):
      """A stand-alone method to evaluate metrics on ranked results.
  
      Note that this method requires for the arguments of the metric to called
      explicitly. So, the correct usage is of the following form:
        tfr.metrics.eval_metric(tfr.metrics.mean_reciprocal_rank,
                                labels=my_labels,
                                predictions=my_scores).
      Here is a simple example showing how to use this method:
        import tensorflow_ranking as tfr
        scores = [[1., 3., 2.], [1., 2., 3.]]
        labels = [[0., 0., 1.], [0., 1., 2.]]
        weights = [[1., 2., 3.], [4., 5., 6.]]
        tfr.metrics.eval_metric(
            metric_fn=tfr.metrics.mean_reciprocal_rank,
            labels=labels,
            predictions=scores,
            weights=weights)
      Args:
        metric_fn: (function) Metric definition. A metric appearing in the
          TF-Ranking metrics module, e.g. tfr.metrics.mean_reciprocal_rank
        **kwargs: A collection of argument values to be passed to the metric, e.g.
          labels and predictions. See `_RankingMetric` and the various metric
          definitions in tfr.metrics for the specifics.
  
      Returns:
        The evaluation of the metric on the input ranked lists.
  
      Raises:
        ValueError: One of the arguments required by the metric is not provided in
          the list of arguments included in kwargs.
  
      """
      metric_spec = inspect.getfullargspec(metric_fn)
      metric_args = metric_spec.args
      required_metric_args = metric_args[
          : -len(metric_spec.defaults)
      ] + [
          n
          for n in metric_spec.kwonlyargs
          if n not in metric_spec.kwonlydefaults
      ]
      for arg in required_metric_args:
          if arg not in kwargs:
              raise ValueError(
                  "Metric %s requires argument %s."
                  % (metric_fn.__name__, arg)
              )
      args = {}
      for arg in kwargs:
          if arg not in metric_args:
              raise ValueError(
                  "Metric %s does not accept argument %s."
                  % (metric_fn.__name__, arg)
              )
          args[arg] = kwargs[arg]
  
      with tf.compat.v1.Session() as sess:
          metric_op, update_op = metric_fn(**args)
          sess.run(tf.compat.v1.local_variables_initializer())
          sess.run([metric_op, update_op])
          return sess.run(metric_op)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import inspect
  import tensorflow
  from tensorflow_ranking.python import metrics_impl
  from tensorflow_ranking.python import utils
label_desc: Use image node_id 14 for calling a global function with example usage: eval_metric(metric_fn) and returns: sess