docs: def _tfidf(x, reduced_term_freq, vocab_size, corpus_size):
    """Maps the terms in x to their (1/doc_length) * inverse document frequency.
    Args:
      x: A `Column` representing int64 values (most likely that are the result
          of calling string_to_int on a tokenized string).
      reduced_term_freq: A dense tensor of shape (vocab_size,) that represents
          the count of the number of documents with each term. So vocab token i (
          which is an int) occures in reduced_term_freq[i] examples in the corpus.
          This means reduced_term_freq should have a count for out-of-vocab tokens
      vocab_size: An int - the count of vocab used to turn the string into int64s
          including any out-of-vocab ids
      corpus_size: A scalar count of the number of documents in the corpus
    Returns:
      A `Column` where each int value is mapped to a double equal to
      (1 if that term appears in that row, 0 otherwise / the number of terms in
      that row) * the log of (the number of rows in `x` / (1 + the number of
      rows in `x` where the term appears at least once))
    NOTE:
      This is intented to be used with the feature_column 'sum' combiner to arrive
      at the true term frequncies.
    """
  
    def _map_to_vocab_range(x):
      """Enforces that the vocab_ids in x are positive."""
      return tf.SparseTensor(
          indices=x.indices,
          values=tf.mod(x.values, vocab_size),
          dense_shape=x.dense_shape)
  
    def _map_to_tfidf(x):
      """Calculates the inverse document frequency of terms in the corpus.
      Args:
        x : a SparseTensor of int64 representing string indices in vocab.
      Returns:
        The tf*idf values
      """
      # Add one to the reduced term freqnencies to avoid dividing by zero.
      idf = tf.log(tf.to_double(corpus_size) / (
          1.0 + tf.to_double(reduced_term_freq)))
  
      dense_doc_sizes = tf.to_double(tf.sparse_reduce_sum(tf.SparseTensor(
          indices=x.indices,
          values=tf.ones_like(x.values),
          dense_shape=x.dense_shape), 1))
  
      # For every term in x, divide the idf by the doc size.
      # The two gathers both result in shape <sum_doc_sizes>
      idf_over_doc_size = (tf.gather(idf, x.values) /
                           tf.gather(dense_doc_sizes, x.indices[:, 0]))
  
      return tf.SparseTensor(
          indices=x.indices,
          values=idf_over_doc_size,
          dense_shape=x.dense_shape)
  
    cleaned_input = _map_to_vocab_range(x)
  
    weights = _map_to_tfidf(cleaned_input)
    return tf.to_float(weights)