def _example_to_dict(example: bytes) -> Dict[str, Optional[np.ndarray]]:
  """Converts serialized tf.Example to Python dictionary."""
  example = tf.train.Example.FromString(example)
  result = {}
  # Sort the produced dict by keys to make the order deterministic.
  for name, feature in sorted(example.features.feature.items()):
    kind = feature.WhichOneof('kind')
    # Use None if the value kind is not set (can occur for passthrough values).
    result[name] = (None if kind is None else np.array(
        getattr(feature, kind).value,
        dtype=_FEATURE_VALUE_KIND_TO_NP_DTYPE[kind]))
  return result
Converts serialized tf.Example to Python dictionary.
tensorflow_transform/impl_helper.py