We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3a95063 + e0b091e commit e0de2d7Copy full SHA for e0de2d7
Chapter-6/document_similarity.py
@@ -39,11 +39,11 @@
39
def compute_cosine_similarity(doc_features, corpus_features,
40
top_n=3):
41
# get document vectors
42
- doc_features = doc_features.toarray()[0]
43
- corpus_features = corpus_features.toarray()
+ doc_features = doc_features[0]
44
# compute similarities
45
similarity = np.dot(doc_features,
46
corpus_features.T)
+ similarity = similarity.toarray()[0]
47
# get docs with highest similarity scores
48
top_docs = similarity.argsort()[::-1][:top_n]
49
top_docs_with_score = [(index, round(similarity[index], 3))
0 commit comments