def to_vocab_range(x: tf.SparseTensor,
                   vocab_size: Union[int, tf.Tensor]) -> tf.SparseTensor:
  """Mods x's int values to enforce that the vocab_ids in x are in range.

  Args:
    x: A int-valued SparseTensor typically representing the vocab indices of
      terms. This is usually the output of tft.compute_and_apply_vocabulary.
    vocab_size: An int or scalar tensor representing the size of vocab. Values
      in x will be mod by this size to avoid negative or out-of-vocab indices.

  Returns:
    A sparse tensor of the same size as x with negative or out-of-vocab values
       normalized.
  """
  return tf.SparseTensor(
      indices=x.indices,
      values=tf.math.mod(x.values, vocab_size),
      dense_shape=x.dense_shape)
Mods x's int values to enforce that the vocab_ids in x are in range.

  Args:
    x: A int-valued SparseTensor typically representing the vocab indices of
      terms. This is usually the output of tft.compute_and_apply_vocabulary.
    vocab_size: An int or scalar tensor representing the size of vocab. Values
      in x will be mod by this size to avoid negative or out-of-vocab indices.

  Returns:
    A sparse tensor of the same size as x with negative or out-of-vocab values
       normalized.
  
tensorflow_transform/tf_utils.py