code: def binary_preference(
      labels,
      predictions,
      weights=None,
      topn=None,
      name=None,
      use_trec_version=True,
  ):
      """Computes binary preference (BPref).
  
      The implementation of BPref is based on the desciption in the following:
      https://trec.nist.gov/pubs/trec15/appendices/CE.MEASURES06.pdf
      BPref = 1 / R SUM_r(1 - |n ranked higher than r| / min(R, N))
  
      Args:
        labels: A `Tensor` of the same shape as `predictions`. A value >= 1 means a
          relevant example.
        predictions: A `Tensor` with shape [batch_size, list_size]. Each value is
          the ranking score of the corresponding example.
        weights: A `Tensor` of the same shape of predictions or [batch_size, 1]. The
          former case is per-example and the latter case is per-list.
        topn: A cutoff for how many examples to consider for this metric.
        name: A string used as the name for this metric.
        use_trec_version: A boolean to choose the version of the formula to use.
          If False, than the alternative BPref formula will be used:
          BPref = 1 / R SUM_r(1 - |n ranked higher than r| / R)
  
      Returns:
        A metric for binary preference metric of the batch.
  
      """
      metric = metrics_impl.BPrefMetric(
          name, topn, use_trec_version=use_trec_version
      )
      with tf.compat.v1.name_scope(
          metric.name,
          "binary_preference",
          (labels, predictions, weights),
      ):
          # TODO: Add mask argument for metric.compute() call
          per_list_bpref, per_list_weights = metric.compute(
              labels, predictions, weights
          )
      return tf.compat.v1.metrics.mean(per_list_bpref, per_list_weights)
  
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 13 for calling a global function with example usage: binary_preference(labels, predictions, weights, topn, name, use_trec_version) and returns: tf