mirror of https://github.com/explosion/spaCy.git
Fix serialization of weight offsets
This commit is contained in:
parent
c044e9c21c
commit
f1acdaab55
|
@ -434,20 +434,20 @@ def model_to_bytes(model):
|
||||||
weights.append(layer._mem.weights)
|
weights.append(layer._mem.weights)
|
||||||
else:
|
else:
|
||||||
weights.append(layer._mem.weights.get())
|
weights.append(layer._mem.weights.get())
|
||||||
metas.append(tuple(layer._mem._offsets))
|
metas.append(layer._mem._offsets)
|
||||||
dims.append(getattr(layer, '_dims', None))
|
dims.append(getattr(layer, '_dims', None))
|
||||||
i += 1
|
i += 1
|
||||||
if hasattr(layer, '_layers'):
|
if hasattr(layer, '_layers'):
|
||||||
queue.extend(layer._layers)
|
queue.extend(layer._layers)
|
||||||
data = {'metas': metas, 'weights': weights, 'dims': dims}
|
data = {'metas': ujson.dumps(metas), 'weights': weights, 'dims': ujson.dumps(dims)}
|
||||||
return msgpack.dumps(data)
|
return msgpack.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
def model_from_bytes(model, bytes_data):
|
def model_from_bytes(model, bytes_data):
|
||||||
data = msgpack.loads(bytes_data)
|
data = msgpack.loads(bytes_data)
|
||||||
weights = data['weights']
|
weights = data['weights']
|
||||||
metas = data['metas']
|
metas = ujson.loads(data['metas'])
|
||||||
dims = data['dims']
|
dims = ujson.loads(data['dims'])
|
||||||
queue = [model]
|
queue = [model]
|
||||||
i = 0
|
i = 0
|
||||||
for layer in queue:
|
for layer in queue:
|
||||||
|
|
Loading…
Reference in New Issue