code: def serialize_slice_key(
      slice_key: SliceKeyType,
  ) -> metrics_for_slice_pb2.SliceKey:
      """Converts SliceKeyType to SliceKey proto.
  
      Args:
        slice_key: The slice key in the format of SliceKeyType.
  
      Returns:
        The slice key in the format of SliceKey proto.
  
      Raises:
        TypeError: If the evaluate type is unrecognized.
      """
      result = metrics_for_slice_pb2.SliceKey()
  
      for col, val in slice_key:
          single_slice_key = result.single_slice_keys.add()
          single_slice_key.column = col
          if isinstance(val, (bytes, str)):
              single_slice_key.bytes_value = tf.compat.as_bytes(val)
          elif isinstance(val, int):
              single_slice_key.int64_value = val
          elif isinstance(val, float):
              single_slice_key.float_value = val
          else:
              raise TypeError(
                  "unrecognized type of type %s, value %s"
                  % (type(val), val)
              )
  
      return result
  
imports: import itertools
  from typing import Any, Callable, Dict, Generator, Iterable, List, NamedTuple, Optional, Tuple, Union
  import apache_beam
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.slicer import slice_accessor
label_desc: Use image node_id 2 for calling a global function with example usage: serialize_slice_key(slice_key) and returns: result