code: def _sequence_schema_as_feature_spec(
      schema: schema_pb2.Schema,
  ) -> SchemaAsFeatureSpecResult:
      """Generates a feature spec from a Schema describing tf.SequenceExample data.
  
      See `tensor_representation_util.CreateTfSequenceExampleParserConfig`s
      docstring for feature spec generation rules.
      We mix context and sequence feature specs to replicate how preprocessing_fn
      sees input features -- as top-level values of a single `inputs` dict. Note
      that this makes the feature spec generation irreversible without additional
      input since it's no longer possible to distinguish context and sequence
      features to produce the original schema.
  
      Args:
        schema: A TFMD Schema proto.
  
      Returns:
        A pair (feature spec, domains) where feature spec is a dict whose keys are
            feature names and values are instances of FixedLenFeature,
            VarLenFeature, SparseFeature or RaggedFeature, and `domains` is a dict
            whose keys are feature names and values are one of the `domain_info`
            oneof, e.g. IntDomain.
  
      Raises:
        ValueError: If `TensorRepresentation`s in the schema result in feature specs
            that are not supported.
      """
      (
          context_feature_spec,
          sequence_feature_spec,
      ) = tensor_representation_util.CreateTfSequenceExampleParserConfig(
          schema
      )
      feature_spec = {**context_feature_spec, **sequence_feature_spec}
      string_domains = _get_string_domains(schema)
      domain_by_feature_name = _get_source_feature_domains(
          schema, string_domains
      )
      domains = {}
      for name, spec in feature_spec.items():
          if isinstance(
              spec, (tf.io.FixedLenFeature, tf.io.VarLenFeature)
          ):
              source_feature_name = name
          elif isinstance(
              spec, (tf.io.SparseFeature, tf.io.RaggedFeature)
          ):
              source_feature_name = spec.value_key
          else:
              raise ValueError("spec is not recognized")
          if source_feature_name in domain_by_feature_name:
              domains[name] = domain_by_feature_name[
                  source_feature_name
              ]
      return SchemaAsFeatureSpecResult(feature_spec, domains)
  
imports: import dataclasses
  import typing
  from typing import Dict, List, Mapping, Optional, Tuple, Union
  import tensorflow
  from tensorflow_transform import common_types
  from tensorflow_transform.tf_metadata import schema_utils_legacy
  from tfx_bsl.tfxio import tensor_representation_util
  from tensorflow_metadata.proto.v0 import path_pb2
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 9 for calling a global function with example usage: _sequence_schema_as_feature_spec(schema) and returns: SchemaAsFeatureSpecResult