Skip to content

Commit

Permalink
Fix loading previous vectors models
Browse files Browse the repository at this point in the history
  • Loading branch information
honnibal committed Oct 31, 2017
1 parent 997a615 commit d90a22a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions spacy/vectors.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,27 @@ cdef class Vectors:
path (unicode / Path): Directory path, string or Path-like object.
RETURNS (Vectors): The modified object.
"""
def load_keys(path):
def load_key2row(path):
if path.exists():
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):
xp = Model.ops.xp
if path.exists():
self.data = xp.load(path)

serializers = OrderedDict((
('key2row', load_keys),
('key2row', load_key2row),
('keys', load_keys),
('vectors', load_vectors),
))
util.from_disk(path, serializers, exclude)
Expand Down

0 comments on commit d90a22a

Please sign in to comment.