From 99982684b0f6588436b1118d7e2978a99c6fac02 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 31 May 2017 14:08:16 -0500 Subject: [PATCH 1/3] Fix normalize_string_keys function' --- spacy/compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spacy/compat.py b/spacy/compat.py index ff73caddd..912c59cc2 100644 --- a/spacy/compat.py +++ b/spacy/compat.py @@ -79,7 +79,7 @@ def is_config(python2=None, python3=None, windows=None, linux=None, osx=None): def normalize_string_keys(old): '''Given a dictionary, make sure keys are unicode strings, not bytes.''' new = {} - for key, value in old: + for key, value in old.items(): if isinstance(key, bytes_): new[key.decode('utf8')] = value else: From 5385a06dd25aebe7f9c06b23954cef1a4ea6d1e8 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 31 May 2017 14:09:08 -0500 Subject: [PATCH 2/3] Require new thinc --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1fca476d1..4d4d3b72e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ pathlib numpy>=1.7 cymem>=1.30,<1.32 preshed>=1.0.0,<2.0.0 -thinc>=6.6.0,<6.7.0 +thinc>=6.6.1,<6.7.0 murmurhash>=0.26,<0.27 plac<1.0.0,>=0.9.6 six diff --git a/setup.py b/setup.py index 093f0c199..acccc3fdf 100755 --- a/setup.py +++ b/setup.py @@ -191,7 +191,7 @@ def setup_package(): 'murmurhash>=0.26,<0.27', 'cymem>=1.30,<1.32', 'preshed>=1.0.0,<2.0.0', - 'thinc>=6.6.0,<6.7.0', + 'thinc>=6.6.1,<6.7.0', 'plac<1.0.0,>=0.9.6', 'pip>=9.0.0,<10.0.0', 'six', From c8a58cfcf8dbe8f421be18f087d86d1279cb6d38 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 31 May 2017 15:21:44 -0500 Subject: [PATCH 3/3] Fix Python2/3 load bug --- spacy/compat.py | 5 +++++ spacy/util.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spacy/compat.py b/spacy/compat.py index 912c59cc2..848ea816a 100644 --- a/spacy/compat.py +++ b/spacy/compat.py @@ -59,6 +59,11 @@ elif is_python3: json_dumps = lambda data: ujson.dumps(data, indent=2) path2str = lambda path: str(path) +def getattr_(obj, name, *default): + if is_python3 and isinstance(name, bytes): + name = name.decode('utf8') + return getattr(obj, name, *default) + def symlink_to(orig, dest): if is_python2 and is_windows: diff --git a/spacy/util.py b/spacy/util.py index dabceb4a8..22533ca39 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -22,7 +22,7 @@ import ujson from .symbols import ORTH from .compat import cupy, CudaStream, path2str, basestring_, input_, unicode_ -from .compat import copy_array, normalize_string_keys +from .compat import copy_array, normalize_string_keys, getattr_ LANGUAGES = {} @@ -499,7 +499,7 @@ def model_from_bytes(model, bytes_data): for dim, value in weights[i]['dims'].items(): setattr(layer, dim, value) for param in weights[i]['params']: - dest = getattr(layer, param['name']) + dest = getattr_(layer, param['name']) copy_array(dest, param['value']) i += 1 if hasattr(layer, '_layers'):