From 4bfc55b532ee4455b214d08eab402917299aa12c Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 17 Mar 2017 08:15:59 -0500 Subject: [PATCH] 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. --- spacy/vocab.pyx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spacy/vocab.pyx b/spacy/vocab.pyx index cce85e095..4c2f2f283 100644 --- a/spacy/vocab.pyx +++ b/spacy/vocab.pyx @@ -533,6 +533,8 @@ cdef class Vocab: vec = 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