docstr: Parameters
  ----------
  term_doc_matrix : TermDocMatrix
      Term document matrix object to compact
  Returns
  -------
  New term doc matrix
docstr_tok: ["Parameters","--","--","--","--","--","term_doc_matrix",":","TermDocMatrix","Term","document","matrix","object","to","compact","Returns","--","--","--","-","New","term","doc","matrix"]
code: def compact(self, term_doc_matrix, verbose=False):
      """
      Parameters
      ----------
      term_doc_matrix : TermDocMatrix
          Term document matrix object to compact
      Returns
      -------
      New term doc matrix
      """
  
      rank_df = self.scorer.get_rank_df(term_doc_matrix)
      optimal_rank = self._find_optimal_rank(rank_df)
  
      terms_to_remove = rank_df.index[
          np.isnan(rank_df[rank_df <= optimal_rank]).apply(
              lambda x: all(x), axis=1
          )
      ]
  
      if self.include_n_most_frequent_terms > 0:
          most_frequent_terms = (
              self.scorer.get_frequencies(term_doc_matrix)
              .sort_values(ascending=False)
              .index[: self.include_n_most_frequent_terms]
          )
          terms_to_remove = set(terms_to_remove) - set(
              most_frequent_terms
          )
  
      compacted_term_doc_matrix = self._remove_terms(
          term_doc_matrix, terms_to_remove
      )
  
      if verbose:
          # print('max terms', self.max_terms,
          #      'optimal_rank', optimal_rank,
          #      'num_terms', compacted_term_doc_matrix.get_num_terms())
          pass
      return compacted_term_doc_matrix
  
imports: from typing import Optional, Tuple
  import pandas
  import numpy
  from scattertext.termscoring.CorpusBasedTermScorer import CorpusBasedTermScorer
  from scipy.stats import rankdata
  from scattertext.termranking.AbsoluteFrequencyRanker import AbsoluteFrequencyRanker
  from scattertext.termscoring.ScaledFScore import ScaledFScorePresetsNeg1To1
label_desc: Use image node_id 2 for calling the AssociationCompactor obj's underlying member method code with example usage: obj.compact(term_doc_matrix, verbose) and returns: compacted_term_doc_matrix