def _num_extreme_words(words, extreme_words, average=True):
    """ Count the number of common words

    Inputs:
        words (list of string): to be checked
        extreme_words (set of string or dict[string] -> float): common words set

    Returns:
        tuple or list of int: # of extreme words in each extreme polars
    """
    if not isinstance(extreme_words, (dict, set)):
        raise Exception('[ERROR] common/rare word list should be set!')
    elif isinstance(extreme_words, list):
        extreme_words = set(extreme_words)

    if not len(extreme_words) > 0:
        raise Exception('[ERROR] no words found!!')

    res = 0
    for word in words:
        if word in extreme_words:
            res += 1

    if average:
        res /= len(extreme_words)

    return res