def _compute_vocabulary_values(x, weights) -> _BatchWeightedVocabulary:
  """Computes a vocabulary for X values.

  Args:
    x: Input `Tensor` or `CompositeTensor`.
    weights: Weights input `Tensor`.

  Returns:
    An XVocabulary object containing the results of the computation. See more in
    the XVocabulary docstring.
  """
  unique_x_values, unique_idx, unique_count = tf.unique_with_counts(
      x, out_idx=tf.int64
  )
  # Counts the occurrences of a given X value
  summed_weights_per_x = tf.math.unsorted_segment_sum(
      weights, unique_idx, tf.size(input=unique_x_values)
  )
  max_x_idx = tf.size(unique_x_values, out_type=tf.int64)
  return _BatchWeightedVocabulary(
      unique_x_values=unique_x_values,
      summed_weights_per_x=summed_weights_per_x,
      unique_count=unique_count,
      unique_idx=unique_idx,
      max_x_idx=max_x_idx,
  )
Computes a vocabulary for X values.

  Args:
    x: Input `Tensor` or `CompositeTensor`.
    weights: Weights input `Tensor`.

  Returns:
    An XVocabulary object containing the results of the computation. See more in
    the XVocabulary docstring.
  
tensorflow_transform/tf_utils.py