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 incompatability in persistence for older versions #1723

Merged
merged 2 commits into from
Nov 20, 2017

Conversation

chinmayapancholi13
Copy link
Contributor

Added load method to class gensim.models.wrappers.fasttext.FastText to set self.wv.syn0_ngrams (present in newer models) using self.wv.syn0_all (present in older models).

Relevant issue : #1642
cc : @Liebeck

@menshikh-iv
Copy link
Contributor

Thanks @chinmayapancholi13, good work 👍

@menshikh-iv menshikh-iv merged commit 51545c2 into piskvorky:develop Nov 20, 2017
Copy link
Owner

@piskvorky piskvorky left a comment

Choose a reason for hiding this comment

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

Comments for code style fixes.

def load(cls, *args, **kwargs):
model = super(FastText, cls).load(*args, **kwargs)
if hasattr(model.wv, 'syn0_all'):
setattr(model.wv, 'syn0_ngrams', model.wv.syn0_all)
Copy link
Owner

Choose a reason for hiding this comment

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

What's with this setattr / delattr? Why not a simple (and more readable) model.wv.syn0_ngrams = model.wv.syn0_all?

self.assertEqual(loaded_model.wv.syn0.shape[1], 10)
self.assertEqual(loaded_model.wv.syn0_ngrams.shape[1], 10)
# in-vocab word
in_expected_vec = numpy.array([-2.44566941, -1.54802394, -2.61103821, -1.88549316, 1.02860415,
Copy link
Owner

@piskvorky piskvorky Nov 20, 2017

Choose a reason for hiding this comment

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

Bad indentation (please use hanging indent).

1.19031894, 2.01627707, 1.98942184, -1.39095843, -0.65036952])
self.assertTrue(numpy.allclose(loaded_model["the"], in_expected_vec, atol=1e-4))
# out-of-vocab word
out_expected_vec = numpy.array([-1.34948218, -0.8686831, -1.51483142, -1.0164026, 0.56272298,
Copy link
Owner

Choose a reason for hiding this comment

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

dtto

VaiyeBe pushed a commit to VaiyeBe/gensim that referenced this pull request Nov 26, 2017
…1642 (piskvorky#1723)

* added 'load' method for fasttext wrapper

* added unit-test for persistence with pre-3.0.0 models
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