code: def compact(self, term_doc_matrix, verbose=False):
      rank_df = self.scorer.get_rank_df(term_doc_matrix)
      p_df = rank_df / rank_df.sum(axis=0) + 0.001
      m = p_df.sum(axis=1)
  
      def lg(x):
          return np.log(x) / np.log(2)
  
      rank_df["Score"] = m * lg(1 / m) - (p_df * lg(1 / p_df)).sum(
          axis=1
      )
      terms_to_remove = (
          rank_df.sort_values(by="Score", ascending=False)
          .iloc[self.max_terms :]
          .index
      )
      return term_doc_matrix.remove_terms(
          terms_to_remove, self.scorer.use_non_text_features
      )
  
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 JSDCompactor obj's underlying member method code with example usage: obj.compact(term_doc_matrix, verbose) and returns: term_doc_matrix, unknown