code: def _to_global_document_frequency(
      x: tf.SparseTensor, vocab_size: Union[int, tf.Tensor]
  ) -> tf.Tensor:
      """Summerizes term/doc one-hot tensor to get document frequency of each term.
  
      Args:
        x: a SparseTensor of size (batch_size, vocab_size) and values 0/1 to
          indicate to existence of each term in each document. x is expected to be
          the output of _to_term_document_one_hot.
        vocab_size: A scalar int64 Tensor - the count of vocab used to turn the
          string into int64s including any OOV buckets.
  
      Returns:
        a tensor with indices as (1, <vocab_index>) and values as the count of
          documents in the entire dataset that contain each vocab term.
      """
      # term_doc_freq is the one-hot encoding of term existence in each document.
      # It is a (batch_size, vocab_size)-shaped, 0/1 valued sparse tensor.
      term_doc_one_hot = _to_term_document_one_hot(x, vocab_size)
  
      # Reduce sum the one-hot tensor within each mini batch to get one
      # (1, vocab_size)-shaped sparse tensor for each mini batch, with the value
      # being the count of documents containing each term in that batch.
      count_docs_with_term = tf.sparse.reduce_sum(
          term_doc_one_hot, axis=0, keepdims=True
      )
  
      # Sum up all batches to get a (1, vocab_size)-shaped sparse tensor storing
      # count of documents containing each term across the entire dataset.
      return analyzers.sum(
          count_docs_with_term, reduce_instance_dims=False
      )
  
file_path: transform/tensorflow_transform/experimental/mappers.py
imports: from typing import Any, Optional, Union, Sequence
  import tensorflow
  from tensorflow_transform import analyzers
  from tensorflow_transform import common
  from tensorflow_transform import common_types
  from tensorflow_transform import mappers
  from tensorflow_transform import tf_utils
  from tensorflow_transform.experimental import analyzers
label_desc: Use image node_id 5 for calling a global function with example usage: _to_global_document_frequency(x, vocab_size) and returns: analyzers