code: def validate_varlen_sparse_value(
      name: str, batched_value: common_types.SparseTensorValueType
  ):
      """Checks that the given SparseTensor is 2-D ragged and left-aligned."""
      indices = np.asarray(batched_value.indices)
      if indices.shape[1] != 2:
          raise ValueError(
              f"Encountered non 2-D varlen sparse feature {name}"
          )
      if indices.shape[0] == 0:
          return
      indices_diff = np.diff(indices, axis=0)
      instance_index_diff, value_index_diff = (
          indices_diff[:, 0],
          indices_diff[:, 1],
      )
      if np.any(instance_index_diff < 0):
          raise ValueError(
              f"Encountered decreasing instance indices for feature {name}: {indices}"
          )
      if np.any(
          np.logical_and(
              instance_index_diff == 0, value_index_diff != 1
          )
      ):
          raise ValueError(
              f"Encountered non-consecutive value indices for feature {name}:"
              f" {indices}"
          )
      (instance_boundaries,) = np.where(instance_index_diff != 0)
      if np.any(indices[np.append(instance_boundaries + 1, 0), 1] != 0):
          raise ValueError(
              f"Encountered non-zero starting value indices for feature {name}:"
              f" {indices}"
          )
  
imports: import functools
  import os
  import re
  from typing import Callable, Dict, List, Mapping, Optional, FrozenSet
  from absl import logging
  import numpy
  import pyarrow
  import tensorflow
  from tensorflow_transform import analyzer_nodes
  from tensorflow_transform import annotators
  from tensorflow_transform import common_types
  from tensorflow_transform import graph_context
  from tensorflow_transform import graph_tools
  from tensorflow_transform import schema_inference
  from tensorflow_transform import tf2_utils
  from tensorflow_transform import tf_utils
  from tensorflow_transform.output_wrapper import TFTransformOutput
  from tensorflow_transform.saved import saved_transform_io
  from tensorflow_transform.saved import saved_transform_io_v2
  from tensorflow_transform.tf_metadata import dataset_metadata
  from tensorflow_transform.tf_metadata import metadata_io
  from tensorflow_transform.tf_metadata import schema_utils
  from tfx_bsl.coders import example_coder
  from tfx_bsl.tfxio import tensor_to_arrow
  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 8 for calling a global function with example usage: validate_varlen_sparse_value(name, batched_value) without return types