code: def test_annotate_sparse_outputs(self, use_tf_compat_v1):
      def preprocessing_fn(inputs):
          outputs = inputs.copy()
          x = tf.sparse.expand_dims(inputs["x"], -1)
          outputs["x"] = x
          tft.experimental.annotate_sparse_output_shape(
              x, tf.constant([1, 1])
          )
          tft.experimental.annotate_sparse_output_shape(
              outputs["y"], [17]
          )
          tft.experimental.annotate_true_sparse_output(outputs["z"])
          return outputs
  
      input_data_dicts = [
          dict(x=[1], y=[2], z=[3], t=[4]) for x in range(10)
      ]
      input_metadata = tft.DatasetMetadata.from_feature_spec(
          {
              "x": tf.io.VarLenFeature(tf.int64),
              "y": tf.io.VarLenFeature(tf.int64),
              "z": tf.io.VarLenFeature(tf.int64),
              "t": tf.io.VarLenFeature(tf.int64),
          }
      )
      schema = text_format.Parse(
          """
          feature {
            name: "t"
            type: INT
          }
          feature {
            name: "x$sparse_indices_0"
            type: INT
            int_domain {
              min: 0
              max: 0
            }
          }
          feature {
            name: "x$sparse_indices_1"
            type: INT
            int_domain {
              min: 0
              max: 0
            }
          }
          feature {
            name: "x$sparse_values"
            type: INT
          }
          feature {
            name: "y$sparse_indices_0"
            type: INT
            int_domain {
              min: 0
              max: 16
            }
          }
          feature {
            name: "y$sparse_values"
            type: INT
          }
          feature {
            name: "z$sparse_indices_0"
            type: INT
          }
          feature {
            name: "z$sparse_values"
            type: INT
          }
          sparse_feature {
            name: "x"
            index_feature {
              name: "x$sparse_indices_0"
            }
            index_feature {
              name: "x$sparse_indices_1"
            }
            is_sorted: true
            value_feature {
              name: "x$sparse_values"
            }
          }
          sparse_feature {
            name: "y"
            index_feature {
              name: "y$sparse_indices_0"
            }
            is_sorted: true
            value_feature {
              name: "y$sparse_values"
            }
          }
          sparse_feature {
            name: "z"
            index_feature {
              name: "z$sparse_indices_0"
            }
            is_sorted: true
            value_feature {
              name: "z$sparse_values"
            }
          }
      """,
          schema_pb2.Schema(),
      )
      if not tft_unit.is_external_environment():
          schema.generate_legacy_feature_spec = False
      self.assertAnalyzeAndTransformResults(
          input_data_dicts,
          input_metadata,
          preprocessing_fn,
          expected_metadata=tft.DatasetMetadata(schema),
          force_tf_compat_v1=use_tf_compat_v1,
          output_record_batches=True,
      )
  
file_path: transform/tensorflow_transform/beam/annotators_test.py
imports: import tensorflow
  import tensorflow_transform
  from tensorflow_transform.beam import tft_unit
  from google.protobuf import text_format
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 1 for calling the AnnotatorsTest obj's underlying member method code with example usage: obj.test_annotate_sparse_outputs(use_tf_compat_v1) and returns: outputs