def _get_approximate_vocabulary_analyzer_inputs(
    x: common_types.TensorType,
    file_format: common_types.VocabularyFileFormatType,
    weights: Optional[common_types.TensorType],
) -> Tuple[common_types.TensorType, common_types.TensorType]:
  """Helper for constructing approximate vocabulary inputs from tensors.

  Args:
    x: `Tensor`, `SparseTensor`, or `RaggedTensor` to compute vocabulary over.
    file_format: The format of the resulting vocabulary file.
      'tfrecord_gzip' requires tensorflow>=2.4.
    weights: Optional `Tensor` of weights.

  Returns:
    A list of batch-reduced `Tensor`s to feed to vocabulary analysis.
  """
  filter_regex = analyzers.get_vocab_newline_characters_regex(
      x.dtype, file_format)
  reduced_batch = tf_utils.reduce_batch_weighted_counts(
      x, weights=weights, force=True, filter_regex=filter_regex)
  assert reduced_batch.summed_positive_per_x_and_y is None
  if weights is None:
    assert reduced_batch.summed_weights_per_x is None
    return (reduced_batch.unique_x, reduced_batch.counts_per_x)
  else:
    return (reduced_batch.unique_x, reduced_batch.summed_weights_per_x)
Helper for constructing approximate vocabulary inputs from tensors.

  Args:
    x: `Tensor`, `SparseTensor`, or `RaggedTensor` to compute vocabulary over.
    file_format: The format of the resulting vocabulary file.
      'tfrecord_gzip' requires tensorflow>=2.4.
    weights: Optional `Tensor` of weights.

  Returns:
    A list of batch-reduced `Tensor`s to feed to vocabulary analysis.
  
tensorflow_transform/experimental/analyzers.py