code: def _to_tfidf(
      term_frequency: tf.SparseTensor,
      reduced_term_freq: tf.Tensor,
      corpus_size: tf.Tensor,
      smooth: bool,
  ) -> tf.SparseTensor:
      """Calculates the inverse document frequency of terms in the corpus.
  
      Args:
        term_frequency: The `SparseTensor` output of _to_term_frequency.
        reduced_term_freq: A `Tensor` of shape (vocabSize,) that represents the
          count of the number of documents with each term.
        corpus_size: A scalar count of the number of documents in the corpus.
        smooth: A bool indicating if the idf value should be smoothed. See
          tfidf_weights documentation for details.
  
      Returns:
        A `SparseTensor` with indices=<doc_index_in_batch>, <term_index_in_vocab>,
        values=term frequency * inverse document frequency,
        and shape=(batch, vocab_size)
      """
      # The idf tensor has shape (vocab_size,)
      idf = tf_utils.document_frequency_to_idf(
          reduced_term_freq,
          corpus_size,
          smooth=smooth,
          add_baseline=True,
      )
      gathered_idfs = tf.gather(
          tf.squeeze(idf), term_frequency.indices[:, 1]
      )
      tfidf_values = tf.cast(
          term_frequency.values, tf.float32
      ) * tf.cast(gathered_idfs, tf.float32)
  
      return tf.SparseTensor(
          indices=term_frequency.indices,
          values=tfidf_values,
          dense_shape=term_frequency.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 16 for calling a global function with example usage: _to_tfidf(term_frequency, reduced_term_freq, corpus_size, smooth) and returns: tf