Skip to content

Commit 9dbe830

Browse files
Corrected smoothing errors and changed default smoothing to 5
1 parent f7e48d5 commit 9dbe830

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

turftopic/feature_importance.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def ctf_idf(
210210
def npmi(
211211
doc_topic_matrix: np.ndarray,
212212
doc_term_matrix: spr.csr_matrix,
213-
smoothing: int = 1,
213+
smoothing: int = 5,
214214
) -> np.ndarray:
215215
eps = np.finfo(float).eps
216216
p_w = np.squeeze(np.asarray(doc_term_matrix.sum(axis=0))) + smoothing
@@ -221,7 +221,10 @@ def npmi(
221221
labels = np.argmax(doc_topic_matrix, axis=1)
222222
p_wt = []
223223
for i in np.arange(doc_topic_matrix.shape[1]):
224-
_p_w = np.squeeze(np.asarray(doc_term_matrix[labels == i].sum(axis=0)))
224+
_p_w = (
225+
np.squeeze(np.asarray(doc_term_matrix[labels == i].sum(axis=0)))
226+
+ smoothing
227+
)
225228
_p_w = _p_w / _p_w.sum()
226229
_p_w[_p_w <= 0] = eps
227230
p_wt.append(_p_w)

0 commit comments

Comments
 (0)