Skip to content

Commit e0de2d7

Browse files
authored
Merge pull request dipanjanS#2 from martijnvanbeers/master
Do the dot-product on the sparse matrix
2 parents 3a95063 + e0b091e commit e0de2d7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Chapter-6/document_similarity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
def compute_cosine_similarity(doc_features, corpus_features,
4040
top_n=3):
4141
# get document vectors
42-
doc_features = doc_features.toarray()[0]
43-
corpus_features = corpus_features.toarray()
42+
doc_features = doc_features[0]
4443
# compute similarities
4544
similarity = np.dot(doc_features,
4645
corpus_features.T)
46+
similarity = similarity.toarray()[0]
4747
# get docs with highest similarity scores
4848
top_docs = similarity.argsort()[::-1][:top_n]
4949
top_docs_with_score = [(index, round(similarity[index], 3))

0 commit comments

Comments
 (0)