code: def create_eager_metrics_internal(
      metric_fns, weights_fn=common_layers.weights_all
  ):
      """Create metrics accumulators and averager for Eager mode.
  
      Args:
        metric_fns: dict<metric name, metric function>
        weights_fn: function that takes labels and returns a weights mask. Defaults
          to weights of all 1, i.e. common_layers.weights_all. Use
          common_layers.weights_nonzero if labels have 0-padding.
  
      Returns:
        (accum_fn(predictions, targets) => None,
         result_fn() => dict<str metric_name, float avg_val>
      """
  
      from tensorflow.contrib.eager.python import (
          tfe,
      )  # pylint: disable=g-import-not-at-top
  
      tfe_metrics = {}
  
      for name in metric_fns:
          tfe_metrics[name] = tfe.metrics.Mean(name=name)
  
      def metric_accum(predictions, targets):
          for name, metric_fn in metric_fns.items():
              val, weight = metric_fn(
                  predictions, targets, weights_fn=weights_fn
              )
              tfe_metrics[name](np.squeeze(val), np.squeeze(weight))
  
      def metric_means():
          avgs = {}
          for name in metric_fns:
              avgs[name] = tfe_metrics[name].result().numpy()
          return avgs
  
      return metric_accum, metric_means
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import six
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import bleu_hook
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import rouge
  from tensor2tensor.utils import sari_hook
  import tensorflow.compat.v1
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 35 for calling a global function with example usage: create_eager_metrics_internal(metric_fns, weights_fn) and returns: metric_accum,  metric_means, avgs