Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed incorrect doctags in most_similar #601 #994

Merged
merged 5 commits into from Nov 9, 2016

Conversation

parulsethi
Copy link
Contributor

most_similar() in doc2vec.py doesn't consider given clip range for tagID/indexes #601
fix: add clip_start to index_to_doctag's indexes.

@tmylk
Copy link
Contributor

tmylk commented Nov 8, 2016

Thanks for the fix.
Please add a line in CHANGELOG and a new test for this.

@@ -460,7 +460,7 @@ def most_similar(self, positive=[], negative=[], topn=10, clip_start=0, clip_end
return dists
best = matutils.argsort(dists, topn=topn + len(all_docs), reverse=True)
# ignore (don't return) docs from the input
result = [(self.index_to_doctag(sim), float(dists[sim])) for sim in best if sim not in all_docs]
result = [(self.index_to_doctag(sim + clip_start), float(dists[sim])) for sim in best if (sim+clip_start) not in all_docs]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: space around binary operators.

@parulsethi
Copy link
Contributor Author

Made the changes mentioned above.
Though there was an unrelated test failure once in test_word2vec here.

@@ -159,6 +160,12 @@ def model_sanity(self, model):
self.assertEqual(list(zip(*sims))[0], list(zip(*sims2))[0]) # same doc ids
self.assertTrue(np.allclose(list(zip(*sims))[1], list(zip(*sims2))[1])) # close-enough dists

# sim results should be in clip range if given
clip_sims = model.docvecs.most_similar(fire1, clip_start=len(model.docvecs)//2, clip_end=len(model.docvecs))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a clip_end as len(model.docvecs)*2//3

@tmylk tmylk merged commit a0443e4 into piskvorky:develop Nov 9, 2016
@tmylk
Copy link
Contributor

tmylk commented Nov 9, 2016

Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants