code: def create_ranking_head(
      loss_fn,
      eval_metric_fns=None,
      optimizer=None,
      train_op_fn=None,
      name=None,
  ):
      """A factory method to create `_RankingHead`.
  
      Args:
        loss_fn: A loss function with the following signature (see make_loss_fn in
          losses.py):
          * Args:
            `labels`: A `Tensor` of the same shape as `logits` representing
              relevance.
            `logits`: A `Tensor` with shape [batch_size, list_size]. Each value is
              the ranking score of the corresponding example.
            `features`: A dict of `Tensor`s for all features.
          * Returns: A scalar containing the loss to be optimized.
        eval_metric_fns: A dict of metric functions keyed by a string name. The
          values of the dict are metric functions with the following signature:
          * Args:
            `labels`: A `Tensor` of the same shape as `predictions` representing
              relevance.
            `predictions`: A `Tensor` with shape [batch_size, list_size]. Each value
              is the ranking score of the corresponding example.
            `features`: A dict of `Tensor`s for all features.
          * Returns: The result of calling a metric function, namely a
            `(metric_tensor, update_op)` tuple.
        optimizer: `Optimizer` instance used to optimize the loss in TRAIN mode.
          Namely, it sets `train_op = optimizer.minimize(loss, global_step)`, which
          updates variables and increments `global_step`.
        train_op_fn: Function that takes a scalar loss `Tensor` and returns
          `train_op`. Used if `optimizer` is `None`.
        name: Name of the head. If provided, will be used as `name_scope` when
          creating ops.
  
      Returns:
        An instance of `_RankingHead` for ranking.
  
      Raises:
        ValueError: If `loss_fn` is not callable.
      """
      if not callable(loss_fn):
          raise ValueError("Not callable loss_fn: {}".format(loss_fn))
  
      return _RankingHead(
          loss_fn=loss_fn,
          eval_metric_fns=eval_metric_fns,
          optimizer=optimizer,
          train_op_fn=train_op_fn,
          name=name,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import six
  import tensorflow
  from tensorflow import estimator
label_desc: Use image node_id 1 for calling a global function with example usage: create_ranking_head(loss_fn, eval_metric_fns, optimizer, train_op_fn, name) and returns: _RankingHead