Skip to content

Commit a133446

Browse files
committed
make dummy mask for corpus-wide keyword extraction
1 parent 30589f7 commit a133446

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

turftopic/models/keynmf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def extract_keywords(
124124
terms = document_term_matrix[i, :].todense()
125125
embedding = embeddings[i].reshape(1, -1)
126126
if self.keyword_scope == 'document':
127-
nonzero = terms > 0
128-
if not np.any(nonzero):
127+
mask = terms > 0
128+
if not np.any(mask):
129129
keywords.append(dict())
130130
continue
131-
important_terms = np.squeeze(np.asarray(nonzero))
132-
word_embeddings = self.vocab_embeddings[important_terms]
133-
sim = cosine_similarity(embedding, word_embeddings)
134131
else:
135-
sim = cosine_similarity(embedding, self.vocab_embeddings)
132+
mask = np.ones(shape=terms.shape, dtype=bool)
133+
important_terms = np.squeeze(np.asarray(mask))
134+
word_embeddings = self.vocab_embeddings[important_terms]
135+
sim = cosine_similarity(embedding, word_embeddings)
136136
sim = np.ravel(sim)
137137
kth = min(self.top_n, len(sim) - 1)
138138
top = np.argpartition(-sim, kth)[:kth]

0 commit comments

Comments
 (0)