(
        self,
        *,
        by: Literal[
            "lemma", "lower", "norm", "orth", "lemma_", "lower_", "norm_", "orth_"
        ] = "lemma",
        weighting: Literal["count", "freq", "idf"] = "count",
        smooth_idf: bool = True,
        **kwargs,
    )
return word_doc_counts_
Map the set of unique words in :class:`Corpus` to their *document* counts
        as absolute, relative, or inverse frequencies of occurence.

        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;
                if "idf", weights are the log of the inverse relative frequencies, i.e.
                ``log(n_docs / word_doc_count)`` or, if ``smooth_idf`` is True,
                ``log(1 + (n_docs / word_doc_count))``.
            smooth_idf: If True, add 1 to all word doc counts when
                calculating "idf" weighting, equivalent to adding a single
                document to the corpus containing every unique word.

        Returns:
            Mapping of a unique word id or string (depending on the value of ``by``)
            to the number of documents in which it appears,
            weighted as absolute, relative, or inverse frequency of occurrence
            (depending on the value of ``weighting``).

        See Also:
            :func:`textacy.vsm.get_doc_freqs() <textacy.vsm.matrix_utils.get_doc_freqs>`
Map the set of unique words in :class:`Corpus` to their *document* counts
        as absolute, relative, or inverse frequencies of occurence.
Map the set of unique words in : class : Corpus to their * document * counts as absolute relative or inverse frequencies of occurence .
def word_doc_counts(
        self,
        *,
        by: Literal[
            "lemma", "lower", "norm", "orth", "lemma_", "lower_", "norm_", "orth_"
        ] = "lemma",
        weighting: Literal["count", "freq", "idf"] = "count",
        smooth_idf: bool = True,
        **kwargs,
    ) -> Dict[int, int | float] | Dict[str, int | float]:
        """
        Map the set of unique words in :class:`Corpus` to their *document* counts
        as absolute, relative, or inverse frequencies of occurence.

        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;
                if "idf", weights are the log of the inverse relative frequencies, i.e.
                ``log(n_docs / word_doc_count)`` or, if ``smooth_idf`` is True,
                ``log(1 + (n_docs / word_doc_count))``.
            smooth_idf: If True, add 1 to all word doc counts when
                calculating "idf" weighting, equivalent to adding a single
                document to the corpus containing every unique word.

        Returns:
            Mapping of a unique word id or string (depending on the value of ``by``)
            to the number of documents in which it appears,
            weighted as absolute, relative, or inverse frequency of occurrence
            (depending on the value of ``weighting``).

        See Also:
            :func:`textacy.vsm.get_doc_freqs() <textacy.vsm.matrix_utils.get_doc_freqs>`
        """
        word_doc_counts_: Union[Counter[Any], Dict[Any, Union[int, float]]]
        word_doc_counts_ = collections.Counter()
        for doc in self:
            word_doc_counts_.update(
                extract.to_bag_of_words(doc, by=by, weighting="binary", **kwargs)
            )
        if weighting == "count":
            word_doc_counts_ = dict(word_doc_counts_)
        elif weighting == "freq":
            n_docs = self.n_docs
            word_doc_counts_ = {
                word: count / n_docs for word, count in word_doc_counts_.items()
            }
        elif weighting == "idf":
            n_docs = self.n_docs
            if smooth_idf is True:
                word_doc_counts_ = {
                    word: math.log1p(n_docs / count)
                    for word, count in word_doc_counts_.items()
                }
            else:
                word_doc_counts_ = {
                    word: math.log(n_docs / count)
                    for word, count in word_doc_counts_.items()
                }
        else:
            raise ValueError(
                errors.value_invalid_msg(
                    "weighting", weighting, {"count", "freq", "idf"}
                )
            )
        return word_doc_counts_
def word_doc_counts ( self , * , by : Literal [ "lemma" , "lower" , "norm" , "orth" , "lemma_" , "lower_" , "norm_" , "orth_" ] = "lemma" , weighting : Literal [ "count" , "freq" , "idf" ] = "count" , smooth_idf : bool = True , * * kwargs , ) -> Dict [ int , int | float ] | Dict [ str , int | float ] : word_doc_counts_ : Union [ Counter [ Any ] , Dict [ Any , Union [ int , float ] ] ] word_doc_counts_ = collections . Counter ( ) for doc in self : word_doc_counts_ . update ( extract . to_bag_of_words ( doc , by = by , weighting = "binary" , * * kwargs ) ) if weighting == "count" : word_doc_counts_ = dict ( word_doc_counts_ ) elif weighting == "freq" : n_docs = self . n_docs word_doc_counts_ = { word : count / n_docs for word , count in word_doc_counts_ . items ( ) } elif weighting == "idf" : n_docs = self . n_docs if smooth_idf is True : word_doc_counts_ = { word : math . log1p ( n_docs / count ) for word , count in word_doc_counts_ . items ( ) } else : word_doc_counts_ = { word : math . log ( n_docs / count ) for word , count in word_doc_counts_ . items ( ) } else : raise ValueError ( errors . value_invalid_msg ( "weighting" , weighting , { "count" , "freq" , "idf" } ) ) return word_doc_counts_