Args: tfs: A sparse matrix of shape (num_samples, num_features) in csr format bns: A numpy array of shape (num_features,)
(tfs, bns)
| 91 | return bns |
| 92 | |
| 93 | def tfbns(tfs, bns): |
| 94 | """ |
| 95 | Args: |
| 96 | tfs: A sparse matrix of shape (num_samples, num_features) |
| 97 | in csr format |
| 98 | bns: A numpy array of shape (num_features,) |
| 99 | """ |
| 100 | cx = tfs.tocoo() |
| 101 | data, rows, cols = [], [], [] |
| 102 | for i, j, v in zip(cx.row, cx.col, cx.data): |
| 103 | data.append(v * bns[j]) |
| 104 | rows.append(i) |
| 105 | cols.append(j) |
| 106 | return csr_matrix((data, (rows, cols)), shape=tfs.shape) |
| 107 | |
| 108 | # Text Preprocessing using tfidf or bns |
| 109 | class TextTransformer(BaseEstimator, TransformerMixin): |