-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Fixed incompatability in persistence for older versions #1723
Conversation
Thanks @chinmayapancholi13, good work 👍 |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dtto
…1642 (piskvorky#1723) * added 'load' method for fasttext wrapper * added unit-test for persistence with pre-3.0.0 models
Added
load
method to classgensim.models.wrappers.fasttext.FastText
to setself.wv.syn0_ngrams
(present in newer models) usingself.wv.syn0_all
(present in older models).Relevant issue : #1642
cc : @Liebeck