srsly icon indicating copy to clipboard operation
srsly copied to clipboard

TypeError: 'escape_forward_slashes' is an invalid keyword argument for this function, when loading SpaCy 3.0 model (Python 3.10)

Open kkoehncke opened this issue 2 years ago • 4 comments

When using Python 3.10.8, getting following error:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/confection/__init__.py", line 495, in try_dump_json
    return srsly.json_dumps(value)
  File "/opt/conda/lib/python3.10/site-packages/srsly/_json_api.py", line 26, in json_dumps
    result = ujson.dumps(data, indent=indent, escape_forward_slashes=False)
TypeError: 'escape_forward_slashes' is an invalid keyword argument for this function

The above exception was the direct cause of the following exception:

 File "/app/ML/util/nlputil.py", line 35, in load_spacy_tokenizer
    nlp = spacy.load("en_core_web_sm", disable=disable)
  File "/opt/conda/lib/python3.10/site-packages/spacy/__init__.py", line 54, in load
    return util.load_model(
  File "/opt/conda/lib/python3.10/site-packages/spacy/util.py", line 432, in load_model
    return load_model_from_package(name, **kwargs)  # type: ignore[arg-type]
  File "/opt/conda/lib/python3.10/site-packages/spacy/util.py", line 468, in load_model_from_package
    return cls.load(vocab=vocab, disable=disable, enable=enable, exclude=exclude, config=config)  # type: ignore[attr-defined]
  File "/opt/conda/lib/python3.10/site-packages/en_core_web_sm/__init__.py", line 10, in load
    return load_model_from_init_py(__file__, **overrides)
  File "/opt/conda/lib/python3.10/site-packages/spacy/util.py", line 649, in load_model_from_init_py
    return load_model_from_path(
  File "/opt/conda/lib/python3.10/site-packages/spacy/util.py", line 506, in load_model_from_path
    nlp = load_model_from_config(
  File "/opt/conda/lib/python3.10/site-packages/spacy/util.py", line 554, in load_model_from_config
    nlp = lang_cls.from_config(
  File "/opt/conda/lib/python3.10/site-packages/spacy/language.py", line 1781, in from_config
    interpolated = filled.interpolate() if not filled.is_interpolated else filled
  File "/opt/conda/lib/python3.10/site-packages/confection/__init__.py", line 196, in interpolate
    return Config().from_str(self.to_str())
  File "/opt/conda/lib/python3.10/site-packages/confection/__init__.py", line 419, in to_str
    flattened.set(section_name, key, try_dump_json(value, node))
  File "/opt/conda/lib/python3.10/site-packages/confection/__init__.py", line 503, in try_dump_json
    raise ConfigValidationError(config=data, desc=err_msg) from e
confection.ConfigValidationError:

Config validation error
Couldn't serialize config value of type <class 'NoneType'>: 'escape_forward_slashes' is an invalid keyword argument for this function. Make sure all values in your config are JSON-serializable. If you want to include Python objects, use a registered function that returns the object instead.
{'train': None, 'dev': None, 'vectors': None, 'init_tok2vec': None}

Has anyone seen this error before?

kkoehncke avatar Jan 26 '23 19:01 kkoehncke

We have not seen that error before.

What code were you using that caused it, and what version of srsly are you using?

It looks like you have a mismatch between ujson and srsly, but that shouldn't happen because srsly uses a vendored ujson.

polm avatar Jan 30 '23 03:01 polm

Closing due to lack of reply, but please feel free to let us know if this is still an issue for you.

polm avatar Feb 02 '23 10:02 polm

@polm I'm using Spacy 3.5.1 on Python 3.8.15 and experiencing the same issue. srsly version is 2.4.6. OS is Debian 10 Buster. My system had ujson installed, I tried uninstalling it but it didn't solve the issue.

The code to reproduce:

bash:
python3 -m spacy download it_core_news_sm
python3:
import spacy

spacy.load("it_core_news_sm")

The full trace

nlp = spacy.load(model_name, exclude=excluded_pipes)
  File "/opt/conda/default/lib/python3.8/site-packages/spacy/__init__.py", line 54, in load
    return util.load_model(
  File "/opt/conda/default/lib/python3.8/site-packages/spacy/util.py", line 442, in load_model
    return load_model_from_package(name, **kwargs)  # type: ignore[arg-type]
  File "/opt/conda/default/lib/python3.8/site-packages/spacy/util.py", line 478, in load_model_from_package
    return cls.load(vocab=vocab, disable=disable, enable=enable, exclude=exclude, config=config)  # type: ignore[attr-defined]
  File "/opt/conda/default/lib/python3.8/site-packages/it_core_news_sm/__init__.py", line 10, in load
    return load_model_from_init_py(__file__, **overrides)
  File "/opt/conda/default/lib/python3.8/site-packages/spacy/util.py", line 659, in load_model_from_init_py
    return load_model_from_path(
  File "/opt/conda/default/lib/python3.8/site-packages/spacy/util.py", line 516, in load_model_from_path
    nlp = load_model_from_config(
  File "/opt/conda/default/lib/python3.8/site-packages/spacy/util.py", line 564, in load_model_from_config
    nlp = lang_cls.from_config(
  File "/opt/conda/default/lib/python3.8/site-packages/spacy/language.py", line 1781, in from_config
    interpolated = filled.interpolate() if not filled.is_interpolated else filled
  File "/opt/conda/default/lib/python3.8/site-packages/confection/__init__.py", line 196, in interpolate
    return Config().from_str(self.to_str())
  File "/opt/conda/default/lib/python3.8/site-packages/confection/__init__.py", line 419, in to_str
    flattened.set(section_name, key, try_dump_json(value, node))
  File "/opt/conda/default/lib/python3.8/site-packages/confection/__init__.py", line 503, in try_dump_json
    raise ConfigValidationError(config=data, desc=err_msg) from e
confection.ConfigValidationError: 

Config validation error
Couldn't serialize config value of type <class 'NoneType'>: 'escape_forward_slashes' is an invalid keyword argument for this function. Make sure all values in your config are JSON-serializable. If you want to include Python objects, use a registered function that returns the object instead.

zafercavdar avatar Mar 24 '23 01:03 zafercavdar

I also have the same problem with spacy 3.7.1 python 3.7.10

wjun0830 avatar Mar 18 '24 14:03 wjun0830