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: Remove the selected `bad_ids` tokens from :class:`~gensim.corpora.dictionary.Dictionary`.
  
  Alternatively, keep selected `good_ids` in :class:`~gensim.corpora.dictionary.Dictionary` and remove the rest.
  
  Parameters
  ----------
  bad_ids : iterable of int, optional
      Collection of word ids to be removed.
  good_ids : collection of int, optional
      Keep selected collection of word ids and remove the rest.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.corpora import Dictionary
      >>>
      >>> corpus = [["máma", "mele", "maso"], ["ema", "má", "máma"]]
      >>> dct = Dictionary(corpus)
      >>> 'ema' in dct.token2id
      True
      >>> dct.filter_tokens(bad_ids=[dct.token2id['ema']])
      >>> 'ema' in dct.token2id
      False
      >>> len(dct)
      4
      >>> dct.filter_tokens(good_ids=[dct.token2id['maso']])
      >>> len(dct)
      1
docstr_tok: ["Remove","the","selected","`","bad_ids","`","tokens","from",":","class",":","`","~gensim.corpora.dictionary.Dictionary","`",".","Alternatively",",","keep","selected","`","good_ids","`","in",":","class",":","`","~gensim.corpora.dictionary.Dictionary","`","and","remove","the","rest",".","Parameters","--","--","--","--","--","bad_ids",":","iterable","of","int",",","optional","Collection","of","word","ids","to","be","removed",".","good_ids",":","collection","of","int",",","optional","Keep","selected","collection","of","word","ids","and","remove","the","rest",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.corpora","import","Dictionary",">",">",">",">",">",">","corpus","=","[","[","``","m\u00e1ma","''",",","``","mele","''",",","``","maso","''","]",",","[","``","ema","''",",","``","m\u00e1","''",",","``","m\u00e1ma","''","]","]",">",">",">","dct","=","Dictionary","(","corpus",")",">",">",">","'ema","'","in","dct.token2id","True",">",">",">","dct.filter_tokens","(","bad_ids=","[","dct.token2id","[","'ema","'","]","]",")",">",">",">","'ema","'","in","dct.token2id","False",">",">",">","len","(","dct",")","4",">",">",">","dct.filter_tokens","(","good_ids=","[","dct.token2id","[","'maso","'","]","]",")",">",">",">","len","(","dct",")","1"]
code: def filter_tokens(self, bad_ids=None, good_ids=None):
      """Remove the selected `bad_ids` tokens from :class:`~gensim.corpora.dictionary.Dictionary`.
  
      Alternatively, keep selected `good_ids` in :class:`~gensim.corpora.dictionary.Dictionary` and remove the rest.
  
      Parameters
      ----------
      bad_ids : iterable of int, optional
          Collection of word ids to be removed.
      good_ids : collection of int, optional
          Keep selected collection of word ids and remove the rest.
  
      Examples
      --------
      .. sourcecode:: pycon
  
          >>> from gensim.corpora import Dictionary
          >>>
          >>> corpus = [["máma", "mele", "maso"], ["ema", "má", "máma"]]
          >>> dct = Dictionary(corpus)
          >>> 'ema' in dct.token2id
          True
          >>> dct.filter_tokens(bad_ids=[dct.token2id['ema']])
          >>> 'ema' in dct.token2id
          False
          >>> len(dct)
          4
          >>> dct.filter_tokens(good_ids=[dct.token2id['maso']])
          >>> len(dct)
          1
  
      """
      if bad_ids is not None:
          bad_ids = set(bad_ids)
          self.token2id = {
              token: tokenid
              for token, tokenid in self.token2id.items()
              if tokenid not in bad_ids
          }
          self.cfs = {
              tokenid: freq
              for tokenid, freq in self.cfs.items()
              if tokenid not in bad_ids
          }
          self.dfs = {
              tokenid: freq
              for tokenid, freq in self.dfs.items()
              if tokenid not in bad_ids
          }
      if good_ids is not None:
          good_ids = set(good_ids)
          self.token2id = {
              token: tokenid
              for token, tokenid in self.token2id.items()
              if tokenid in good_ids
          }
          self.cfs = {
              tokenid: freq
              for tokenid, freq in self.cfs.items()
              if tokenid in good_ids
          }
          self.dfs = {
              tokenid: freq
              for tokenid, freq in self.dfs.items()
              if tokenid in good_ids
          }
      self.compactify()
  
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 15 for calling the Dictionary obj's underlying member method code with example usage: obj.filter_tokens(bad_ids, good_ids) without return types