code: def MetricsPlotsAndValidationsWriter(  # pylint: disable=invalid-name
      output_paths: Dict[str, str],
      eval_config: config_pb2.EvalConfig,
      add_metrics_callbacks: Optional[
          List[types.AddMetricsCallbackType]
      ] = None,
      metrics_key: str = constants.METRICS_KEY,
      plots_key: str = constants.PLOTS_KEY,
      attributions_key: str = constants.ATTRIBUTIONS_KEY,
      validations_key: str = constants.VALIDATIONS_KEY,
      output_file_format: str = _TFRECORD_FORMAT,
      rubber_stamp: Optional[bool] = False,
      stage_name: str = METRICS_PLOTS_AND_VALIDATIONS_WRITER_STAGE_NAME,
  ) -> writer.Writer:
      """Returns metrics and plots writer.
  
      Note, sharding will be enabled by default if a output_file_format is provided.
      The files will be named <output_path>-SSSSS-of-NNNNN.<output_file_format>
      where SSSSS is the shard number and NNNNN is the number of shards.
  
      Args:
        output_paths: Output paths keyed by output key (e.g. 'metrics', 'plots',
          'validation').
        eval_config: Eval config.
        add_metrics_callbacks: Optional list of metric callbacks (if used).
        metrics_key: Name to use for metrics key in Evaluation output.
        plots_key: Name to use for plots key in Evaluation output.
        attributions_key: Name to use for attributions key in Evaluation output.
        validations_key: Name to use for validations key in Evaluation output.
        output_file_format: File format to use when saving files. Currently
          'tfrecord' and 'parquet' are supported and 'tfrecord is the default'.
          If using parquet, the output metrics and plots files will contain two
          columns, 'slice_key' and 'serialized_value'. The 'slice_key' column will
          be a structured column matching the metrics_for_slice_pb2.SliceKey proto.
          The 'serialized_value' column will contain a serialized MetricsForSlice or
          PlotsForSlice proto. The validation result file will contain a single
          column 'serialized_value' which will contain a single serialized
          ValidationResult proto.
        rubber_stamp: True if this model is being rubber stamped. When a model is
          rubber stamped diff thresholds will be ignored if an associated baseline
          model is not passed.
        stage_name: The stage name to use when this writer is added to the Beam
          pipeline.
      """
      return writer.Writer(
          stage_name=stage_name,
          ptransform=_WriteMetricsPlotsAndValidations(  # pylint: disable=no-value-for-parameter
              output_paths=output_paths,
              eval_config=eval_config,
              add_metrics_callbacks=add_metrics_callbacks or [],
              metrics_key=metrics_key,
              plots_key=plots_key,
              attributions_key=attributions_key,
              validations_key=validations_key,
              output_file_format=output_file_format,
              rubber_stamp=rubber_stamp,
          ),
      )
  
imports: import itertools
  import os
  from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  from absl import logging
  import apache_beam
  import numpy
  import pyarrow
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.evaluators import evaluator
  from tensorflow_model_analysis.evaluators import metrics_validator
  from tensorflow_model_analysis.metrics import calibration_plot
  from tensorflow_model_analysis.metrics import confusion_matrix_plot
  from tensorflow_model_analysis.metrics import metric_specs
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.post_export_metrics import metric_keys
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.proto import validation_result_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.utils import math_util
  from tensorflow_model_analysis.writers import writer
  from google.protobuf import wrappers_pb2
label_desc: Use image node_id 13 for calling a global function with example usage: MetricsPlotsAndValidationsWriter(output_paths, eval_config, add_metrics_callbacks, metrics_key, plots_key, attributions_key, validations_key, output_file_format, rubber_stamp, stage_name) and returns: writer