Fix loading previous vectors models

This commit is contained in:
Matthew Honnibal 2017-10-31 19:58:35 +01:00
parent 997a61557a
commit d90a22afe6

View File

@ -307,9 +307,18 @@ cdef class Vectors:
path (unicode / Path): Directory path, string or Path-like object. path (unicode / Path): Directory path, string or Path-like object.
RETURNS (Vectors): The modified object. RETURNS (Vectors): The modified object.
""" """
def load_keys(path): def load_key2row(path):
if path.exists(): if path.exists():
self.key2row = msgpack.load(path.open('rb')) self.key2row = msgpack.load(path.open('rb'))
for key, row in self.key2row.items():
if row in self._unset:
self._unset.remove(row)
def load_keys(path):
if path.exists():
keys = numpy.load(str(path))
for i, key in enumerate(keys):
self.add(key, row=i)
def load_vectors(path): def load_vectors(path):
xp = Model.ops.xp xp = Model.ops.xp
@ -317,7 +326,8 @@ cdef class Vectors:
self.data = xp.load(path) self.data = xp.load(path)
serializers = OrderedDict(( serializers = OrderedDict((
('key2row', load_keys), ('key2row', load_key2row),
('keys', load_keys),
('vectors', load_vectors), ('vectors', load_vectors),
)) ))
util.from_disk(path, serializers, exclude) util.from_disk(path, serializers, exclude)