We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f7e48d5 commit 9dbe830Copy full SHA for 9dbe830
1 file changed
turftopic/feature_importance.py
@@ -210,7 +210,7 @@ def ctf_idf(
210
def npmi(
211
doc_topic_matrix: np.ndarray,
212
doc_term_matrix: spr.csr_matrix,
213
- smoothing: int = 1,
+ smoothing: int = 5,
214
) -> np.ndarray:
215
eps = np.finfo(float).eps
216
p_w = np.squeeze(np.asarray(doc_term_matrix.sum(axis=0))) + smoothing
@@ -221,7 +221,10 @@ def npmi(
221
labels = np.argmax(doc_topic_matrix, axis=1)
222
p_wt = []
223
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)))
+ _p_w = (
225
+ np.squeeze(np.asarray(doc_term_matrix[labels == i].sum(axis=0)))
226
+ + smoothing
227
+ )
228
_p_w = _p_w / _p_w.sum()
229
_p_w[_p_w <= 0] = eps
230
p_wt.append(_p_w)
0 commit comments