Make set_vector add word to vocab. Fixes #1807

This commit is contained in:
Matthew Honnibal 2018-01-14 13:57:57 +01:00
parent 55754f0cee
commit 0153220304
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,14 @@
'''Test vocab.set_vector also adds the word to the vocab.'''
from __future__ import unicode_literals
from ...vocab import Vocab
import numpy
def test_issue1807():
vocab = Vocab()
arr = numpy.ones((50,), dtype='f')
assert 'hello' not in vocab
vocab.set_vector('hello', arr)
assert 'hello' in vocab

View File

@ -335,6 +335,7 @@ cdef class Vocab:
else:
width = self.vectors.shape[1]
self.vectors.resize((new_rows, width))
lex = self[orth] # Adds worse to vocab
self.vectors.add(orth, vector=vector)
self.vectors.add(orth, vector=vector)