code: def _mean_attributions(
      absolute: bool = True,
      name: str = MEAN_ATTRIBUTIONS_NAME,
      eval_config: Optional[config_pb2.EvalConfig] = None,
      model_name: str = "",
      output_name: str = "",
      sub_key: Optional[metric_types.SubKey] = None,
      example_weighted: bool = False,
  ) -> metric_types.MetricComputations:
      """Returns metric computations for mean attributions."""
      key = metric_types.AttributionsKey(
          name=name,
          model_name=model_name,
          output_name=output_name,
          sub_key=sub_key,
          example_weighted=example_weighted,
      )
  
      # Make sure total_attributions is calculated.
      computations = _total_attributions_computations(
          absolute=absolute,
          eval_config=eval_config,
          model_name=model_name,
          output_name=output_name,
          sub_key=sub_key,
          example_weighted=example_weighted,
      )
      total_attributions_key = computations[-1].keys[-1]
      # Make sure example_count is calculated
      computations.extend(
          example_count.example_count(
              model_names=[model_name],
              output_names=[output_name],
              sub_keys=[sub_key],
              example_weighted=example_weighted,
          )
      )
      example_count_key = computations[-1].keys[-1]
  
      def result(
          metrics: Dict[metric_types.MetricKey, Any]
      ) -> Dict[
          metric_types.AttributionsKey,
          Dict[str, Union[float, np.ndarray]],
      ]:
          """Returns mean attributions."""
          total_attributions = metrics[total_attributions_key]
          count = metrics[example_count_key]
          attributions = {}
          for k, v in total_attributions.items():
              if np.isclose(count, 0.0):
                  attributions[k] = float("nan")
              else:
                  attributions[k] = v / count
          return {key: attributions}
  
      derived_computation = metric_types.DerivedMetricComputation(
          keys=[key], result=result
      )
      computations.append(derived_computation)
      return computations
  
imports: import functools
  from typing import Any, Dict, Iterable, List, Optional, Union
  import apache_beam
  import numpy
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.metrics import example_count
  from tensorflow_model_analysis.metrics import metric_specs
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 2 for calling a global function with example usage: _mean_attributions(absolute, name, eval_config, model_name, output_name, sub_key, example_weighted) and returns: computations, dict