File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ]
You can’t perform that action at this time.
0 commit comments