def _standardize_default_value(
    spec: tf.io.FixedLenFeature) -> tf.io.FixedLenFeature:
  """Converts bytes to strings and unwraps lists with a single element."""
  if spec.default_value is None:
    return spec
  default_value = spec.default_value
  assert isinstance(default_value, list), spec.default_value
  # Convert bytes to string
  if spec.dtype == tf.string:

    # Handle bytes string by trying to decode them (for legacy backwards
    # compatibility) and if failed, keep the default value as bytes.
    def try_decode(value: bytes) -> Union[str, bytes]:
      try:
        return value.decode('utf-8')
      except UnicodeError:
        return value

    default_value = [try_decode(value) for value in default_value]
  # Unwrap a list with a single element.
  if len(default_value) == 1:
    default_value = default_value[0]
  return tf.io.FixedLenFeature(
      shape=spec.shape, dtype=spec.dtype, default_value=default_value)
Converts bytes to strings and unwraps lists with a single element.
tensorflow_transform/tf_metadata/schema_utils.py