class_docstr: Dictionary encapsulates the mapping between normalized words and their integer ids.
  
  Notable instance attributes:
  
  Attributes
  ----------
  token2id : dict of (str, int)
      token -> token_id. I.e. the reverse mapping to `self[token_id]`.
  cfs : dict of (int, int)
      Collection frequencies: token_id -> how many instances of this token are contained in the documents.
  dfs : dict of (int, int)
      Document frequencies: token_id -> how many documents contain this token.
  num_docs : int
      Number of documents processed.
  num_pos : int
      Total number of corpus positions (number of processed words).
  num_nnz : int
      Total number of non-zeroes in the BOW matrix (sum of the number of unique
      words per document over the entire corpus).
class_docstr_tok: ["Dictionary","encapsulates","the","mapping","between","normalized","words","and","their","integer","ids",".","Notable","instance","attributes",":","Attributes","--","--","--","--","--","token2id",":","dict","of","(","str",",","int",")","token","-",">","token_id",".","I.e",".","the","reverse","mapping","to","`","self","[","token_id","]","`",".","cfs",":","dict","of","(","int",",","int",")","Collection","frequencies",":","token_id","-",">","how","many","instances","of","this","token","are","contained","in","the","documents",".","dfs",":","dict","of","(","int",",","int",")","Document","frequencies",":","token_id","-",">","how","many","documents","contain","this","token",".","num_docs",":","int","Number","of","documents","processed",".","num_pos",":","int","Total","number","of","corpus","positions","(","number","of","processed","words",")",".","num_nnz",":","int","Total","number","of","non-zeroes","in","the","BOW","matrix","(","sum","of","the","number","of","unique","words","per","document","over","the","entire","corpus",")","."]
docstr: Assign new word ids to all words, shrinking any gaps.
docstr_tok: ["Assign","new","word","ids","to","all","words",",","shrinking","any","gaps","."]
code: def compactify(self):
      """Assign new word ids to all words, shrinking any gaps."""
      logger.debug("rebuilding dictionary, shrinking gaps")
  
      # build mapping from old id -> new id
      idmap = dict(
          zip(sorted(self.token2id.values()), range(len(self.token2id)))
      )
  
      # reassign mappings to new ids
      self.token2id = {
          token: idmap[tokenid]
          for token, tokenid in self.token2id.items()
      }
      self.id2token = {}
      self.dfs = {
          idmap[tokenid]: freq for tokenid, freq in self.dfs.items()
      }
      self.cfs = {
          idmap[tokenid]: freq for tokenid, freq in self.cfs.items()
      }
  
imports: from collections import defaultdict
  from collections.abc import Mapping
  import logging
  import itertools
  from typing import Optional, List, Tuple
  from gensim import utils
label_desc: Use image node_id 16 for calling the Dictionary obj's underlying member method code with example usage: obj.compactify() without return types