(doc_or_tokens: types.DocOrTokens)
return itertoolz.count(itertoolz.unique(word.lower for word in words))
Compute the number of *unique* words in a document.

    Args:
        doc_or_tokens: If a spaCy ``Doc``, non-punctuation tokens (words) are extracted;
            if an iterable of spaCy ``Token`` s, all non-punct elements are used.
Compute the number of *unique* words in a document.
Compute the number of * unique * words in a document .
def n_unique_words(doc_or_tokens: types.DocOrTokens) -> int:
    """
    Compute the number of *unique* words in a document.

    Args:
        doc_or_tokens: If a spaCy ``Doc``, non-punctuation tokens (words) are extracted;
            if an iterable of spaCy ``Token`` s, all non-punct elements are used.
    """
    words = utils.get_words(doc_or_tokens)
    # NOTE: this stdlib solution is slower than itertoolz for docs with ~250+ words
    # so let's take a small hit on short docs for the sake of big wins on long docs
    # return len({word.lower for word in words})
    return itertoolz.count(itertoolz.unique(word.lower for word in words))
def n_unique_words ( doc_or_tokens : types . DocOrTokens ) -> int : words = utils . get_words ( doc_or_tokens ) # NOTE: this stdlib solution is slower than itertoolz for docs with ~250+ words # so let's take a small hit on short docs for the sake of big wins on long docs # return len({word.lower for word in words}) return itertoolz . count ( itertoolz . unique ( word . lower for word in words ) )