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

Fix Issue #743, Updated word2vec.n_similarities and test_word2vec.testSimilarities methods #883

Merged
merged 17 commits into from
Sep 26, 2016

Conversation

pranay360
Copy link
Contributor

@pranay360 pranay360 commented Sep 25, 2016

Changes requested in PR #882 completed

  1. word2vec.n_similarities now raise a ZeroDivisionError when atleast 1 empty list is passed to it.
  2. In test_word2vec.testSimilarities added testcases involving empty lists to check if ZeroDivisionError is raised.
  3. pep8 followed

Fixes Issue piskvorky#743, n_similarity method now raises ZeroDivisionError if atleast one empty list is passed to it.
Added new test cases in testSimilarities method which makes sure whether ZeroDivisionError is raised if atleast one empty list is passed to word2vec.n_similarities method
Related to fix for issue piskvorky#743
@pranay360 pranay360 changed the title Fix Issue #743, Updated gensim.word2vec.n_similarities and gensim.test.test_word2vec.testSimilarities methods Fix Issue #743, Updated word2vec.n_similarities and test_word2vec.testSimilarities methods Sep 25, 2016
@@ -1,11 +1,10 @@
Changes
=======

0.13.2, 2016-08-19
* export_phrases in Phrases model changed. Fixed issue #794 and added test cases in test/test_phrases.py(@AadityaJ,
[#879](https://github.com/RaRe-Technologies/gensim/pull/879))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't delete from changelog of phrases fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't delete it, I had a previous build in which that entry was not in the changelog, anyway I added it. Thank You for marking out the changes.

matutils.unitvec(array(v2).mean(axis=0)))
else:
raise ZeroDivisionError('Atleast one of the passed list is empty.')
return
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to return.

It is more concise to just have one statement above

if not (len(ws1) > 0 and len(ws2) > 0) :
    raise ZeroDivisionError('Atleast one of the passed list is empty.')

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tmylk & @pranay360 – Two concerns: (1) 'at least' is two words; (2) shouldn't ZeroDivisionError be reserved for cases where an actual division-by-zero occurs? (Passing in unusable values – like empty lists – would seem to call for a ValueError instead.)

Copy link
Owner

Choose a reason for hiding this comment

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

Agreed with @gojomo .

* wordtopics has changed to word_topics in ldamallet, and fixed issue #764. (@bhargavvader, [#771](https://github.com/RaRe-Technologies/gensim/pull/771))

* Fixed issue #743 , In word2vec's n_similarity method if atleast one empty list is passed ZeroDivisionError is raised.
* export_phrases in Phrases model changed. Fixed issue #794 and added test cases in test/test_phrases.py(@AadityaJ, #879) bigram construction can now support multiple bigrams within one sentence
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add to future release 0.13.3

- bigram construction can now support multiple bigrams within one sentence
* wordtopics has changed to word_topics in ldamallet, and fixed issue #764. (@bhargavvader, [#771](https://github.com/RaRe-Technologies/gensim/pull/771))

* export_phrases in Phrases model changed. Fixed issue #794 and added test cases in test/test_phrases.py(@AadityaJ, #879) bigram construction can now support multiple bigrams within one sentence
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you talking about fixing the issue?

- bigram construction can now support multiple bigrams within one sentence
* wordtopics has changed to word_topics in ldamallet, and fixed issue #764. (@bhargavvader, [#771](https://github.com/RaRe-Technologies/gensim/pull/771))

* export_phrases in Phrases model changed. Fixed issue #794 and added test cases in test/test_phrases.py(@AadityaJ, #879) bigram construction can now support multiple bigrams within one sentence
Copy link
Contributor

Choose a reason for hiding this comment

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

This pr is about #743. There is no need to change other parts of changelog.md

v1 = [self[word] for word in ws1]
v2 = [self[word] for word in ws2]
return dot(matutils.unitvec(array(v1).mean(axis=0)), matutils.unitvec(array(v2).mean(axis=0)))
return dot(matutils.unitvec(array(v1).mean(axis=0)),
Copy link
Owner

Choose a reason for hiding this comment

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

We don't use vertical indent in gensim -- change to normal hanging indent (see PEP8: all statements on new lines, one level of indent).

@@ -1539,9 +1539,13 @@ def n_similarity(self, ws1, ws2):
True

"""
if not(len(ws1) and len(ws2)):
raise ZeroDivisionError('Atleast one of the passed list is empty.')
Copy link
Owner

Choose a reason for hiding this comment

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

If input is a list, idiomatic Python is: if not ws1 or not ws2:.

@piskvorky
Copy link
Owner

Code style changes requested; please fix.

This has already been merged, so probably in another PR. Cheers.

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.

4 participants