def filter_extremes(self, no_below=5, no_above=0.5, keep_n=100000):
    'Filter tokens in dictionary by frequency.\n\n        Parameters\n        ----------\n        no_below : int, optional\n            Keep tokens which are contained in at least `no_below` documents.\n        no_above : float, optional\n            Keep tokens which are contained in no more than `no_above` documents\n            (fraction of total corpus size, not an absolute number).\n        keep_n : int, optional\n            Keep only the first `keep_n` most frequent tokens.\n\n        Notes\n        -----\n        For tokens that appear in:\n\n        #. Less than `no_below` documents (absolute number) or \n\n        #. More than `no_above` documents (fraction of total corpus size, **not absolute number**).\n        #. After (1) and (2), keep only the first `keep_n` most frequent tokens (or keep all if `None`).\n\n        Since :class:`~gensim.corpora.hashdictionary.HashDictionary` id range is fixed and doesn\'t depend on the number\n        of tokens seen, this doesn\'t really "remove" anything.\n        It only clears some supplementary statistics, for easier debugging and a smaller RAM footprint.\n\n        Examples\n        --------\n        >>> from gensim.corpora import HashDictionary\n        >>>\n        >>> corpus = [["máma", "mele", "maso"], ["ema", "má", "máma"]]\n        >>> dct = HashDictionary(corpus)\n        >>> dct.filter_extremes(no_below=1, no_above=0.5, keep_n=1)\n        >>> print dct.token2id\n        {\'maso\': 15025}\n\n        '
    no_above_abs = int((no_above * self.num_docs))
    ok = [item for item in iteritems(self.dfs_debug) if (no_below <= item[1] <= no_above_abs)]
    ok = frozenset((word for (word, freq) in sorted(ok, key=(lambda x: (- x[1])))[:keep_n]))
    self.dfs_debug = {word: freq for (word, freq) in iteritems(self.dfs_debug) if (word in ok)}
    self.token2id = {token: tokenid for (token, tokenid) in iteritems(self.token2id) if (token in self.dfs_debug)}
    self.id2token = {tokenid: {token for token in tokens if (token in self.dfs_debug)} for (tokenid, tokens) in iteritems(self.id2token)}
    self.dfs = {tokenid: freq for (tokenid, freq) in iteritems(self.dfs) if self.id2token.get(tokenid, set())}
    logger.info('kept statistics for which were in no less than %i and no more than %i (=%.1f%%) documents', no_below, no_above_abs, (100.0 * no_above))
Filter tokens in dictionary by frequency.

Parameters
----------
no_below : int, optional
    Keep tokens which are contained in at least `no_below` documents.
no_above : float, optional
    Keep tokens which are contained in no more than `no_above` documents
    (fraction of total corpus size, not an absolute number).
keep_n : int, optional
    Keep only the first `keep_n` most frequent tokens.

Notes
-----
For tokens that appear in:

#. Less than `no_below` documents (absolute number) or 

#. More than `no_above` documents (fraction of total corpus size, **not absolute number**).
#. After (1) and (2), keep only the first `keep_n` most frequent tokens (or keep all if `None`).

Since :class:`~gensim.corpora.hashdictionary.HashDictionary` id range is fixed and doesn't depend on the number
of tokens seen, this doesn't really "remove" anything.
It only clears some supplementary statistics, for easier debugging and a smaller RAM footprint.

Examples
--------
>>> from gensim.corpora import HashDictionary
>>>
>>> corpus = [["máma", "mele", "maso"], ["ema", "má", "máma"]]
>>> dct = HashDictionary(corpus)
>>> dct.filter_extremes(no_below=1, no_above=0.5, keep_n=1)
>>> print dct.token2id
{'maso': 15025}
def filter_extremes(self, no_below=5, no_above=0.5, keep_n=100000):
    'Filter tokens in dictionary by frequency.\n\n        Parameters\n        ----------\n        no_below : int, optional\n            Keep tokens which are contained in at least `no_below` documents.\n        no_above : float, optional\n            Keep tokens which are contained in no more than `no_above` documents\n            (fraction of total corpus size, not an absolute number).\n        keep_n : int, optional\n            Keep only the first `keep_n` most frequent tokens.\n\n        Notes\n        -----\n        For tokens that appear in:\n\n        #. Less than `no_below` documents (absolute number) or \n\n        #. More than `no_above` documents (fraction of total corpus size, **not absolute number**).\n        #. After (1) and (2), keep only the first `keep_n` most frequent tokens (or keep all if `None`).\n\n        Since :class:`~gensim.corpora.hashdictionary.HashDictionary` id range is fixed and doesn\'t depend on the number\n        of tokens seen, this doesn\'t really "remove" anything.\n        It only clears some supplementary statistics, for easier debugging and a smaller RAM footprint.\n\n        Examples\n        --------\n        >>> from gensim.corpora import HashDictionary\n        >>>\n        >>> corpus = [["máma", "mele", "maso"], ["ema", "má", "máma"]]\n        >>> dct = HashDictionary(corpus)\n        >>> dct.filter_extremes(no_below=1, no_above=0.5, keep_n=1)\n        >>> print dct.token2id\n        {\'maso\': 15025}\n\n        '
    no_above_abs = int((no_above * self.num_docs))
    ok = [item for item in iteritems(self.dfs_debug) if (no_below <= item[1] <= no_above_abs)]
    ok = frozenset((word for (word, freq) in sorted(ok, key=(lambda x: (- x[1])))[:keep_n]))
    self.dfs_debug = {word: freq for (word, freq) in iteritems(self.dfs_debug) if (word in ok)}
    self.token2id = {token: tokenid for (token, tokenid) in iteritems(self.token2id) if (token in self.dfs_debug)}
    self.id2token = {tokenid: {token for token in tokens if (token in self.dfs_debug)} for (tokenid, tokens) in iteritems(self.id2token)}
    self.dfs = {tokenid: freq for (tokenid, freq) in iteritems(self.dfs) if self.id2token.get(tokenid, set())}
    logger.info('kept statistics for which were in no less than %i and no more than %i (=%.1f%%) documents', no_below, no_above_abs, (100.0 * no_above))