From 04c32aa09172535129a42e0d98f70a3370b2d1a4 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 29 May 2017 13:53:32 +0200 Subject: [PATCH] Fix for serialization --- spacy/util.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spacy/util.py b/spacy/util.py index 9c7562e3f..48d760fc5 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -437,10 +437,10 @@ def model_to_bytes(model): i = 0 for layer in queue: if hasattr(layer, '_mem'): - if layer._mem.weights.size: + if isinstance(layer._mem.weights, numpy.ndarray): weights.append(layer._mem.weights) else: - weights.append(None) + weights.append(layer._mem.weights.get()) metas.append(tuple(layer._mem._offsets)) dims.append(getattr(layer, '_dims', None)) i += 1 @@ -461,10 +461,9 @@ def model_from_bytes(model, bytes_data): for layer in queue: if hasattr(layer, '_mem'): params = weights[i] - if params is not None: - flat_mem = layer._mem._mem.ravel() - flat_params = params.ravel() - flat_mem[:flat_params.size] = flat_params + flat_mem = layer._mem._mem.ravel() + flat_params = params.ravel() + flat_mem[:flat_params.size] = flat_params layer._mem._offsets.update(metas[i]) if hasattr(layer, '_dims'): layer._dims.update(dims[i])