(
        self,
        *,
        by: Literal[
            "lemma", "lower", "norm", "orth", "lemma_", "lower_", "norm_", "orth_"
        ] = "lemma",
        weighting: Literal["count", "freq"] = "count",
        **kwargs,
    )
return word_counts_
Map the set of unique words in :class:`Corpus` to their counts as
        absolute, relative, or binary frequencies of occurence, similar to
        :meth:`Doc._.to_bag_of_words() <textacy.extract.to_bag_of_words>`
        but aggregated over all docs.

        Args:
            by: Attribute by which spaCy ``Token`` s are grouped before counting,
                as given by ``getattr(token, by)``.
                If "lemma", tokens are grouped by their base form w/o inflections;
                if "lower", by the lowercase form of the token text;
                if "norm", by the normalized form of the token text;
                if "orth", by the token text exactly as it appears in documents.
                To output keys as strings, append an underscore to any of these options;
                for example, "lemma_" groups tokens by their lemmas as strings.
            weighting: Type of weighting to assign to unique words given by ``by``.
                If "count", weights are the absolute number of occurrences (i.e. counts);
                if "freq", weights are counts normalized by the total token count,
                giving their relative frequency of occurrence.
            **kwargs: Passed directly on to :func:`textacy.extract.words()`
                - filter_stops: If True, stop words are removed before counting.
                - filter_punct: If True, punctuation tokens are removed before counting.
                - filter_nums: If True, number-like tokens are removed before counting.

        Returns:
            Mapping of a unique word id or string (depending on the value of ``by``)
            to its absolute, relative, or binary frequency of occurrence
            (depending on the value of ``weighting``).

        See Also:
            :func:`textacy.representations.matrix_utils.get_term_freqs()`
Map the set of unique words in :class:`Corpus` to their counts as
        absolute, relative, or binary frequencies of occurence, similar to
        :meth:`Doc._.to_bag_of_words() <textacy.extract.to_bag_of_words>`
        but aggregated over all docs.
Map the set of unique words in : class : Corpus to their counts as absolute relative or binary frequencies of occurence similar to : meth : Doc . _ . to_bag_of_words () <textacy . extract . to_bag_of_words > but aggregated over all docs .
def word_counts(
        self,
        *,
        by: Literal[
            "lemma", "lower", "norm", "orth", "lemma_", "lower_", "norm_", "orth_"
        ] = "lemma",
        weighting: Literal["count", "freq"] = "count",
        **kwargs,
    ) -> Dict[int, int | float] | Dict[str, int | float]:
        """
        Map the set of unique words in :class:`Corpus` to their counts as
        absolute, relative, or binary frequencies of occurence, similar to
        :meth:`Doc._.to_bag_of_words() <textacy.extract.to_bag_of_words>`
        but aggregated over all docs.

        Args:
            by: Attribute by which spaCy ``Token`` s are grouped before counting,
                as given by ``getattr(token, by)``.
                If "lemma", tokens are grouped by their base form w/o inflections;
                if "lower", by the lowercase form of the token text;
                if "norm", by the normalized form of the token text;
                if "orth", by the token text exactly as it appears in documents.
                To output keys as strings, append an underscore to any of these options;
                for example, "lemma_" groups tokens by their lemmas as strings.
            weighting: Type of weighting to assign to unique words given by ``by``.
                If "count", weights are the absolute number of occurrences (i.e. counts);
                if "freq", weights are counts normalized by the total token count,
                giving their relative frequency of occurrence.
            **kwargs: Passed directly on to :func:`textacy.extract.words()`
                - filter_stops: If True, stop words are removed before counting.
                - filter_punct: If True, punctuation tokens are removed before counting.
                - filter_nums: If True, number-like tokens are removed before counting.

        Returns:
            Mapping of a unique word id or string (depending on the value of ``by``)
            to its absolute, relative, or binary frequency of occurrence
            (depending on the value of ``weighting``).

        See Also:
            :func:`textacy.representations.matrix_utils.get_term_freqs()`
        """
        word_counts_: Union[Counter[Any], Dict[Any, Union[int, float]]]
        word_counts_ = collections.Counter()
        for doc in self:
            word_counts_.update(
                extract.to_bag_of_words(doc, by=by, weighting="count", **kwargs)
            )
        if weighting == "count":
            word_counts_ = dict(word_counts_)
        elif weighting == "freq":
            n_tokens = self.n_tokens
            word_counts_ = {
                word: count / n_tokens for word, count in word_counts_.items()
            }
        else:
            raise ValueError(
                errors.value_invalid_msg("weighting", weighting, {"count", "freq"})
            )
        return word_counts_
def word_counts ( self , * , by : Literal [ "lemma" , "lower" , "norm" , "orth" , "lemma_" , "lower_" , "norm_" , "orth_" ] = "lemma" , weighting : Literal [ "count" , "freq" ] = "count" , * * kwargs , ) -> Dict [ int , int | float ] | Dict [ str , int | float ] : word_counts_ : Union [ Counter [ Any ] , Dict [ Any , Union [ int , float ] ] ] word_counts_ = collections . Counter ( ) for doc in self : word_counts_ . update ( extract . to_bag_of_words ( doc , by = by , weighting = "count" , * * kwargs ) ) if weighting == "count" : word_counts_ = dict ( word_counts_ ) elif weighting == "freq" : n_tokens = self . n_tokens word_counts_ = { word : count / n_tokens for word , count in word_counts_ . items ( ) } else : raise ValueError ( errors . value_invalid_msg ( "weighting" , weighting , { "count" , "freq" } ) ) return word_counts_