(self, doc_term_matrix: sp.csr_matrix)
return doc_term_matrix
Re-weight values in a doc-term matrix according to parameters specified
        in :class:`Vectorizer` initialization: binary or tf-idf weighting,
        sublinear term-frequency, document-normalized weights.

        Args:
            doc_term_matrix

        Returns:
            Reweighted doc-term matrix.
Re-weight values in a doc-term matrix according to parameters specified
        in :class:`Vectorizer` initialization: binary or tf-idf weighting,
        sublinear term-frequency, document-normalized weights.
Re - weight values in a doc - term matrix according to parameters specified in : class : Vectorizer initialization : binary or tf - idf weighting sublinear term - frequency document - normalized weights .
def _reweight_values(self, doc_term_matrix: sp.csr_matrix) -> sp.csr_matrix:
        """
        Re-weight values in a doc-term matrix according to parameters specified
        in :class:`Vectorizer` initialization: binary or tf-idf weighting,
        sublinear term-frequency, document-normalized weights.

        Args:
            doc_term_matrix

        Returns:
            Reweighted doc-term matrix.
        """
        # re-weight the local components (term freqs)
        if self.tf_type == "binary":
            doc_term_matrix.data.fill(1)
        elif self.tf_type == "bm25":
            if not self.dl_type:
                doc_term_matrix.data = (
                    doc_term_matrix.data
                    * (BM25_K1 + 1.0)
                    / (BM25_K1 + doc_term_matrix.data)
                )
            else:
                dls = get_doc_lengths(doc_term_matrix, type_=self.dl_type)
                length_norm = (1 - BM25_B) + (BM25_B * (dls / self._avg_doc_length))
                doc_term_matrix = doc_term_matrix.tocoo(copy=False)
                doc_term_matrix.data = (
                    doc_term_matrix.data
                    * (BM25_K1 + 1.0)
                    / (
                        doc_term_matrix.data
                        + (BM25_K1 * length_norm[doc_term_matrix.row])
                    )
                )
                doc_term_matrix = doc_term_matrix.tocsr(copy=False)
        elif self.tf_type == "sqrt":
            _ = np.sqrt(doc_term_matrix.data, doc_term_matrix.data, casting="unsafe")
        elif self.tf_type == "log":
            _ = np.log(doc_term_matrix.data, doc_term_matrix.data, casting="unsafe")
            doc_term_matrix.data += 1.0
        elif self.tf_type == "linear":
            pass  # tfs are already linear
        else:
            # this should never raise, i'm just being a worrywart
            raise ValueError(
                errors.value_invalid_msg(
                    "tf_type", self.tf_type, {"binary", "bm25", "sqrt", "log", "linear"}
                )
            )

        # apply the global component (idfs), column-wise
        if self.idf_type:
            doc_term_matrix = doc_term_matrix * self._idf_diag

        # apply normalizations, row-wise
        # unless we've already handled it for bm25-style tf
        if self.dl_type and self.tf_type != "bm25":
            n_docs, _ = doc_term_matrix.shape
            dls = get_doc_lengths(doc_term_matrix, type_=self.dl_type)
            dl_diag = sp.spdiags(1.0 / dls, diags=0, m=n_docs, n=n_docs, format="csr")
            doc_term_matrix = dl_diag * doc_term_matrix
        if self.norm is not None:
            doc_term_matrix = normalize_mat(
                doc_term_matrix, norm=self.norm, axis=1, copy=False
            )

        return doc_term_matrix
def _reweight_values ( self , doc_term_matrix : sp . csr_matrix ) -> sp . csr_matrix : # re-weight the local components (term freqs) if self . tf_type == "binary" : doc_term_matrix . data . fill ( 1 ) elif self . tf_type == "bm25" : if not self . dl_type : doc_term_matrix . data = ( doc_term_matrix . data * ( BM25_K1 + 1.0 ) / ( BM25_K1 + doc_term_matrix . data ) ) else : dls = get_doc_lengths ( doc_term_matrix , type_ = self . dl_type ) length_norm = ( 1 - BM25_B ) + ( BM25_B * ( dls / self . _avg_doc_length ) ) doc_term_matrix = doc_term_matrix . tocoo ( copy = False ) doc_term_matrix . data = ( doc_term_matrix . data * ( BM25_K1 + 1.0 ) / ( doc_term_matrix . data + ( BM25_K1 * length_norm [ doc_term_matrix . row ] ) ) ) doc_term_matrix = doc_term_matrix . tocsr ( copy = False ) elif self . tf_type == "sqrt" : _ = np . sqrt ( doc_term_matrix . data , doc_term_matrix . data , casting = "unsafe" ) elif self . tf_type == "log" : _ = np . log ( doc_term_matrix . data , doc_term_matrix . data , casting = "unsafe" ) doc_term_matrix . data += 1.0 elif self . tf_type == "linear" : pass # tfs are already linear else : # this should never raise, i'm just being a worrywart raise ValueError ( errors . value_invalid_msg ( "tf_type" , self . tf_type , { "binary" , "bm25" , "sqrt" , "log" , "linear" } ) ) # apply the global component (idfs), column-wise if self . idf_type : doc_term_matrix = doc_term_matrix * self . _idf_diag # apply normalizations, row-wise # unless we've already handled it for bm25-style tf if self . dl_type and self . tf_type != "bm25" : n_docs , _ = doc_term_matrix . shape dls = get_doc_lengths ( doc_term_matrix , type_ = self . dl_type ) dl_diag = sp . spdiags ( 1.0 / dls , diags = 0 , m = n_docs , n = n_docs , format = "csr" ) doc_term_matrix = dl_diag * doc_term_matrix if self . norm is not None : doc_term_matrix = normalize_mat ( doc_term_matrix , norm = self . norm , axis = 1 , copy = False ) return doc_term_matrix