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'):