from typing import List


def filter_dictionary(
    text_docs: List[str], no_below: int = 10, no_above: float = 0.2, **kwargs
):
    """Filters words outside specified frequency thresholds.

    Args:
        text_docs: A list of list of words from a document, can include n-grams up to 3.
        no_below: Keep tokens which are contained in at least no_below documents.
            Default is 10.
        no_above: Keep tokens which are contained in no more than no_above portion of
            documents (fraction of total corpus size). Default is 0.2.
        **kwargs: Other arguments to be passed to gensim.corpora.Dictionary.filter_extremes

    Returns:
        dictionary: Gensim Dictionary encapsulates the mapping between normalized words
            and their integer ids.
        corpus: Bag of Words (BoW) representation of documents (token_id, token_count).
    """
    dictionary = _compat["gensim"].corpora.Dictionary(text_docs)  # type: ignore
    dictionary.filter_extremes(no_below=no_below, no_above=no_above, **kwargs)
    corpus = [dictionary.doc2bow(doc) for doc in text_docs]
    return dictionary, corpus