code: def SliceKeyExtractor(
      slice_spec: Optional[List[slicer.SingleSliceSpec]] = None,
      eval_config: Optional[config_pb2.EvalConfig] = None,
      materialize: Optional[bool] = True,
  ) -> extractor.Extractor:
      """Creates an extractor for extracting slice keys.
  
      The incoming Extracts must contain features stored under tfma.FEATURES_KEY
      and optionally under tfma.TRANSFORMED_FEATURES.
  
      The extractor's PTransform yields a copy of the Extracts input with an
      additional extract pointing at the list of SliceKeyType values keyed by
      tfma.SLICE_KEY_TYPES_KEY. If materialize is True then a materialized version
      of the slice keys will be added under the key tfma.SLICE_KEYS_KEY.
  
      Args:
        slice_spec: Deprecated (use EvalConfig).
        eval_config: Optional EvalConfig containing slicing_specs specifying the
          slices to slice the data into. If slicing_specs are empty, defaults to
          overall slice.
        materialize: True to add MaterializedColumn entries for the slice keys.
  
      Returns:
        Extractor for slice keys.
      """
      if slice_spec and eval_config:
          raise ValueError(
              "slice_spec is deprecated, only use eval_config"
          )
      if eval_config:
          slice_spec = [
              slicer.SingleSliceSpec(spec=spec)
              for spec in eval_config.slicing_specs
          ]
          for cross_slice_spec in eval_config.cross_slicing_specs:
              baseline_slice_spec = slicer.SingleSliceSpec(
                  spec=cross_slice_spec.baseline_spec
              )
              if baseline_slice_spec not in slice_spec:
                  slice_spec.append(baseline_slice_spec)
              for spec in cross_slice_spec.slicing_specs:
                  comparison_slice_spec = slicer.SingleSliceSpec(
                      spec=spec
                  )
                  if comparison_slice_spec not in slice_spec:
                      slice_spec.append(comparison_slice_spec)
      if not slice_spec:
          slice_spec = [slicer.SingleSliceSpec()]
      return extractor.Extractor(
          stage_name=SLICE_KEY_EXTRACTOR_STAGE_NAME,
          ptransform=ExtractSliceKeys(
              slice_spec, eval_config, materialize
          ),
      )
  
file_path: model-analysis/tensorflow_model_analysis/extractors/slice_key_extractor.py
imports: import copy
  from typing import List, Optional
  import apache_beam
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.extractors import extractor
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 1 for calling a global function with example usage: SliceKeyExtractor(slice_spec, eval_config, materialize) and returns: extractor