code: def _override_sparse_feature_annotated_shapes(
      feature_spec: Dict[str, common_types.FeatureSpecType],
      sparse_output_annotations: Dict[str, List[Union[int, str]]],
  ):
      """Overrides feature_spec SparseFeatures with annotated shapes."""
      for k in sparse_output_annotations:
          if k not in feature_spec:
              raise ValueError(
                  f'Shape annotation for feature "{k}" which is not an output feature.'
              )
  
          if not isinstance(
              feature := feature_spec[k], tf.io.SparseFeature
          ):
              logging.warning(
                  'Feature "%s" was annotated with a sparse shape but it is not'
                  " sparse: %s",
                  k,
                  feature,
              )
              continue
  
          annotations = sparse_output_annotations[k]
  
          # Otherwise, the feature was just annotated to be truely sparse.
          if any(isinstance(t, (str, bytes)) for t in annotations):
              logging.warning(
                  'Feature "%s" was annotated to be sparse without setting a shape.',
                  k,
              )
              continue
  
          feature_spec[k] = tf.io.SparseFeature(
              index_key=feature.index_key,
              value_key=feature.value_key,
              dtype=feature.dtype,
              size=tf.TensorShape(annotations),
              already_sorted=feature.already_sorted,
          )
  
imports: import collections
  import itertools
  from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Tuple, Union
  from absl import logging
  import tensorflow
  from tensorflow_transform import common
  from tensorflow_transform import common_types
  from tensorflow_transform import graph_context
  from tensorflow_transform import tf2_utils
  from tensorflow_transform import tf_utils
  from tensorflow_transform.saved import saved_transform_io_v2
  from tensorflow_transform.tf_metadata import schema_utils
  from tfx_bsl.tfxio import tensor_representation_util
  from google.protobuf import any_pb2
  from tensorflow.python.eager import function
  from tensorflow.python.framework import ops
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 6 for calling a global function with example usage: _override_sparse_feature_annotated_shapes(feature_spec, sparse_output_annotations) without return types