code: def _make_auc_metric_fn(curve, label_vocabulary):
      """Makes a metric_fn to compute AUC-ROC or AUC-PR.
  
      Wraps around tf.metrics.auc(), so that it is easier to keep track of the
      metric name with the string key. This only works in the single-task
      binary-classification setup.
  
      Args:
        curve: "ROC" or "PR".
        label_vocabulary: A 1-D string Tensor or string list. If `label_vocabulary`
          is None, then the labels are assumed to be castable to bool.
  
      Returns:
        A function that takes `labels` and `predictions`, and returns a dictionary
        mapping "auc_roc" or "auc_pr" to (tensor, update_op) tuples.
      """
  
      def _metric_fn(labels, predictions, weights=None):
          """Metrics for tensorboard.
  
          Args:
            labels: A 1-D Tensor castable to bool, where True means that the label for
              that instance is class 1, and False means that the label for that
              instance is class 0.
            predictions: A dictionary mapping strings to Tensors. This dictionary
              contains a `predictions` string key which maps to a tf.int64 Tensor, as
              well as `probabilities` and `log_probabilities` string keys which map to
              tf.float32 Tensors. The `probabilities` key must map to a 2-D tf.float32
              Tensor with values in range [0, 1]. The first dimension of this Tensor
              is over the examples, and the second dimension is over the classes.
            weights: weights for the metric. Works only for one label tensor.
  
          Returns:
            A dictionary mapping "auc_roc" or "auc_pr" to (tensor, update_op) tuples.
  
          Raises:
            NotImplementedError: if user tries to use this in a multi-task setup.
            ValueError: if predictions["probabilities"] is not a 2-D Tensor,
              or if the second dimension is not 2, or if labels has dtype string but
              label_vocabulary is not provided.
          """
  
          if isinstance(labels, dict):
              raise NotImplementedError(
                  "Multi-task setup is not yet implemented for AUC."
              )
  
          if predictions["probabilities"].shape.rank != 2:
              raise ValueError(
                  "predictions['probabilities'] must have a 2-D Tensor, where the "
                  "first dimension is over the examples, and the second dimension is "
                  "over the classes."
              )
  
          if predictions["probabilities"].shape.dims[-1] != 2:
              raise ValueError(
                  "The second dimension of predictions['probabilities'] must be 2, "
                  "because this AUC function is only defined for binary "
                  "classification."
              )
  
          if labels.dtype == tf.string:
              if not label_vocabulary:
                  raise ValueError(
                      "labels is of dtype string, but label_vocabulary is not present."
                  )
              else:
                  initializer = tf.lookup.KeyValueTensorInitializer(
                      keys=label_vocabulary,
                      values=range(len(label_vocabulary)),
                      name="class_id_lookup",
                      value_dtype=tf.int64,
                  )
                  table = tf.lookup.StaticVocabularyTable(
                      initializer, 1, name="lookup"
                  )
                  label_ids = table.lookup(labels)
          else:
              label_ids = labels
  
          return {
              "auc_{}".format(curve.lower()): tf.compat.v1.metrics.auc(
                  label_ids,
                  tf.unstack(predictions["probabilities"], axis=-1)[1],
                  curve=curve,
                  weights=weights,
                  summation_method="careful_interpolation",
              )
          }
  
      return _metric_fn
  
imports: from absl import logging
  import tensorflow.compat.v2
label_desc: Use image node_id 2 for calling a global function with example usage: _make_auc_metric_fn(curve, label_vocabulary) and returns: _metric_fn, dict