code: def make_accuracy_metric_fn(label_vocabulary=None):
      """Makes a metric_fn for accuracy from an optional label_vocabulary.
  
      Args:
        label_vocabulary: A 1-D string Tensor or string list (in the single task
          setup); or a dictionary mapping string keys to those (in the multi task
          setup). The string keys correspond to the task name, allowing different
          tasks to have different label vocabularies. If `label_vocabulary` does not
          contain the task name as a key, or `label_vocabulary` is None, then the
          task is assumed to have int64 labels.
  
      Returns:
        A function that takes `labels` and `predictions`, and returns a dictionary
        mapping metric names to (tensor, update_op) tuples.
      """
  
      def _metric_fn(labels, predictions, weights=None):
          """Metrics for tensorboard.
  
          Args:
            labels: A int64 Tensor or a string Tensor; or a dictionary mapping task
              names (strings) to those. If a task name maps to a string Tensor, then
              label_vocabulary needs to contain that task name as a key as well,
              otherwise the task name would not have metrics computed for it.
            predictions: A dictionary mapping strings to Tensors. This dictionary
              always contains a `predictions` string key. For regression, the
              `predictions` key maps to a tf.float32 Tensor. For classification, the
              `predictions` key maps to a tf.int64 Tensor, and the dictionary also
              contains `probabilities` and `log_probabilities` string keys which map
              to tf.float32 Tensors. In the multi task setup, the dictionary also
              contains task-specific keys, such as `predictions/task_a`, and the
              `predictions` key maps to the primary task predictions.
            weights: weights for the metric. Works only for one label tensor.
  
          Returns:
            A dictionary mapping string to (tensor, update_op) tuples. In the single
            task setup, the dictionary contains only the `accuracy` key. In the
            multi task setup, the dictionary contains the task name suffixed keys,
            e.g., `accuracy/task_a` mapping to their respective accuracy metric
            tuples.
          """
  
          metrics_dict = {}
  
          if not isinstance(labels, dict):
              if labels.dtype == tf.string and label_vocabulary:
                  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)
                  metrics_dict[
                      "accuracy"
                  ] = tf.compat.v1.metrics.accuracy(
                      label_ids,
                      predictions["predictions"],
                      weights=weights,
                  )
              elif labels.dtype.is_integer and not label_vocabulary:
                  metrics_dict[
                      "accuracy"
                  ] = tf.compat.v1.metrics.accuracy(
                      labels,
                      predictions["predictions"],
                      weights=weights,
                  )
              elif (
                  labels.dtype.is_floating
                  and not label_vocabulary
                  and tf.squeeze(labels).shape
                  == tf.squeeze(predictions["predictions"]).shape
              ):
                  metrics_dict[
                      "accuracy"
                  ] = tf.compat.v1.metrics.accuracy(
                      tf.cast(labels, "int32"),
                      predictions["predictions"],
                      weights=weights,
                  )
              else:
                  logging.warning(
                      "Unable to compute accuracy, since labels has dtype "
                      "tf.string but label_vocabulary is not supplied."
                  )
  
          else:
              for task_name, label in labels.items():
                  if (
                      label.dtype == tf.string
                      and label_vocabulary
                      and task_name in label_vocabulary
                  ):
                      initializer = tf.lookup.KeyValueTensorInitializer(
                          keys=label_vocabulary[task_name],
                          values=range(
                              len(label_vocabulary[task_name])
                          ),
                          name="class_id_lookup",
                          value_dtype=tf.int64,
                      )
                      table = tf.lookup.StaticVocabularyTable(
                          initializer, 1, name="lookup"
                      )
                      label_ids = table.lookup(label)
                      metrics_dict[
                          "accuracy/" + task_name
                      ] = tf.compat.v1.metrics.accuracy(
                          label_ids,
                          predictions["predictions/" + task_name],
                      )
                  elif label.dtype.is_integer and (
                      not label_vocabulary
                      or task_name not in label_vocabulary
                  ):
                      metrics_dict[
                          "accuracy/" + task_name
                      ] = tf.compat.v1.metrics.accuracy(
                          label, predictions["predictions/" + task_name]
                      )
                  elif (
                      label.dtype.is_floating
                      and (
                          not label_vocabulary
                          or task_name not in label_vocabulary
                      )
                      and tf.squeeze(label).shape
                      == tf.squeeze(
                          predictions["predictions/" + task_name]
                      ).shape
                  ):
                      metrics_dict[
                          "accuracy/" + task_name
                      ] = tf.compat.v1.metrics.accuracy(
                          tf.cast(label, "int32"),
                          predictions["predictions/" + task_name],
                      )
                  else:
                      logging.warning(
                          "Unable to compute accuracy for task %s, since labels has dtype "
                          "tf.string but label_vocabulary is not supplied.",
                          task_name,
                      )
  
          return metrics_dict
  
      return _metric_fn
  
imports: from absl import logging
  import tensorflow.compat.v2
label_desc: Use image node_id 1 for calling a global function with example usage: make_accuracy_metric_fn(label_vocabulary) and returns: _metric_fn, metrics_dict