code: def _deduplicate_tensor_per_row(input_tensor, batch_dim):
      """Helper function for deduplicating each row of the provided tensor.
  
      For each input row, computes the unique values and set them in positions 0
      through num_unique - 1 within the row.
  
      Args:
        input_tensor: A `Tensor` or `SparseTensor` to be deuplicated per row.
        batch_dim: The batch dimension or number of "rows" in the batch.
  
      Returns:
        A  `SparseTensor` containing the unique set of values from each
          row of the input. Note: the original order of the input may not be
          preserved.
      """
      max_unique = tf.constant(0, dtype=tf.int64)
      values = tf.TensorArray(
          size=batch_dim,
          dtype=input_tensor.dtype,
          element_shape=[None],
          infer_shape=False,
      )
      indices = tf.TensorArray(
          size=batch_dim,
          dtype=tf.int64,
          element_shape=[None, 2],
          infer_shape=False,
      )
  
      def _deduplicate_row(dedup_row_loop_vars):
          """Deduplicates the values in the i-th row of the input.
  
          Args:
            dedup_row_loop_vars: A _DedupRowLoopVars NamedTuple.
  
          Returns:
            Updated version of the _DedupRowLoopVars for the loop iteration.
          """
          (
              index,
              input_tensor,
              indices,
              values,
              max_unique,
          ) = dedup_row_loop_vars
          if isinstance(input_tensor, tf.SparseTensor):
              row = tf.sparse.slice(
                  input_tensor,
                  [index, 0],
                  [1, input_tensor.dense_shape[1]],
              )
              row_values, _ = tf.unique(row.values)
          else:
              row = input_tensor[index]
              row_values, _ = tf.unique(row)
  
          # Keep track of the maximum number of unique elements in a row, as this
          # will determine the resulting dense shape.
          max_unique = tf.cast(
              tf.maximum(
                  tf.cast(tf.shape(row_values)[0], tf.int64), max_unique
              ),
              tf.int64,
          )
          column_indices = tf.cast(
              tf.expand_dims(tf.range(tf.shape(row_values)[0]), axis=1),
              tf.int64,
          )
          row_indices = tf.fill(
              tf.shape(column_indices), tf.cast(index, tf.int64)
          )
          values = values.write(index, row_values)
          indices = indices.write(
              index, tf.concat([row_indices, column_indices], 1)
          )
          return [
              _DedupRowLoopVars(
                  index + 1, input_tensor, indices, values, max_unique
              )
          ]
  
      index = tf.constant(0, tf.int32)
      (loop_output,) = tf.while_loop(
          lambda loop_args: loop_args.index < batch_dim,
          _deduplicate_row,
          [
              _DedupRowLoopVars(
                  index, input_tensor, indices, values, max_unique
              )
          ],
          back_prop=False,
      )
  
      dense_shape = tf.convert_to_tensor(
          [
              tf.cast(batch_dim, tf.int64),
              tf.cast(loop_output.max_unique, tf.int64),
          ],
          dtype=tf.int64,
      )
      return tf.SparseTensor(
          indices=tf.cast(loop_output.indices.concat(), tf.int64),
          values=loop_output.values.concat(),
          dense_shape=dense_shape,
      )
  
imports: import os
  from typing import Any, Callable, Iterable, Optional, Tuple, Union
  import tensorflow
  from tensorflow_transform import analyzers
  from tensorflow_transform import common
  from tensorflow_transform import common_types
  from tensorflow_transform import gaussianization
  from tensorflow_transform import schema_inference
  from tensorflow_transform import tf_utils
  from tfx_bsl.types import tfx_namedtuple
label_desc: Use image node_id 25 for calling a global function with example usage: _deduplicate_tensor_per_row(input_tensor, batch_dim) and returns: tf, list