Auto-add words to vocab when loading vectors

When calling vocab.load_vectors_from_bin_loc, ensure that missing
entries are added to the vocab. Otherwise, loading vectors into an
empty vocab object resulted in no vectors being added.
This commit is contained in:
Matthew Honnibal 2017-03-17 08:15:59 -05:00
parent 271997a146
commit 4bfc55b532

View File

@ -533,6 +533,8 @@ cdef class Vocab:
vec = <float*>file_.alloc_read(self.mem, vec_len, sizeof(float))
string_id = self.strings[chars[:word_len]]
# Insert words into vocab to add vector.
self.get_by_orth(self.mem, string_id)
while string_id >= vectors.size():
vectors.push_back(EMPTY_VEC)
assert vec != NULL