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 1651: make word_vec() return immutable vector #1662

Merged
merged 5 commits into from
Oct 30, 2017

Conversation

CLearERR
Copy link
Contributor

fix for issue about mutable vector returned by KeyedVectors.word_vector

else:
return self.syn0[self.vocab[word].index]
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you remove this branch? We must raise an exception if word not in the dictionary.

raise KeyError("word '%s' not in vocabulary" % word)
result = self.syn0[self.vocab[word].index]

result.setflags(write=False)
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 test to check this behaviour (with Exception catching)

@@ -386,6 +386,12 @@ def test_delete_temporary_training_data(self):
self.model_sanity(model, keep_training=False)
self.assertTrue(hasattr(model, 'syn1neg'))

def test_word_vec(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

More-descriptive name would be better, such as test_word_vec_non_writeable().

@gojomo gojomo changed the title Fix 1651 Fix 1651: make word_vec() return immutable vector Oct 29, 2017
@gojomo
Copy link
Collaborator

gojomo commented Oct 29, 2017

Ideally PR names should be descriptive even if issue-numbers (like #1651) are ignored/unknown. So I've updated the name to be more descriptive.

@piskvorky
Copy link
Owner

piskvorky commented Oct 29, 2017

On github, PR titles do not link through to the issues (the pingback doesn't appear in the linked issue, no easy to way to visit the issue from the PR).

Please use the native Github formatting, it makes maintenance easier.

@menshikh-iv
Copy link
Contributor

Thanks @CLearERR, congratz with the first 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.

4 participants