mirror of https://github.com/explosion/spaCy.git
Don't interpolate config on Language deserialization
This commit is contained in:
parent
e1e1760fd6
commit
daac8ebacd
|
@ -1542,7 +1542,9 @@ class Language:
|
|||
path = util.ensure_path(path)
|
||||
deserializers = {}
|
||||
if Path(path / "config.cfg").exists():
|
||||
deserializers["config.cfg"] = lambda p: self.config.from_disk(p)
|
||||
deserializers["config.cfg"] = lambda p: self.config.from_disk(
|
||||
p, interpolate=False
|
||||
)
|
||||
deserializers["meta.json"] = deserialize_meta
|
||||
deserializers["vocab"] = deserialize_vocab
|
||||
deserializers["tokenizer"] = lambda p: self.tokenizer.from_disk(
|
||||
|
@ -1605,7 +1607,9 @@ class Language:
|
|||
self.vocab.vectors.name = data.get("vectors", {}).get("name")
|
||||
|
||||
deserializers = {}
|
||||
deserializers["config.cfg"] = lambda b: self.config.from_bytes(b)
|
||||
deserializers["config.cfg"] = lambda b: self.config.from_bytes(
|
||||
b, interpolate=False
|
||||
)
|
||||
deserializers["meta.json"] = deserialize_meta
|
||||
deserializers["vocab"] = self.vocab.from_bytes
|
||||
deserializers["tokenizer"] = lambda b: self.tokenizer.from_bytes(
|
||||
|
|
|
@ -209,6 +209,20 @@ def test_config_nlp_roundtrip():
|
|||
assert new_nlp._factory_meta == nlp._factory_meta
|
||||
|
||||
|
||||
def test_config_nlp_roundtrip_bytes_disk():
|
||||
"""Test that the config is serialized correctly and not interpolated
|
||||
by mistake."""
|
||||
nlp = English()
|
||||
nlp_bytes = nlp.to_bytes()
|
||||
new_nlp = English().from_bytes(nlp_bytes)
|
||||
assert new_nlp.config == nlp.config
|
||||
nlp = English()
|
||||
with make_tempdir() as d:
|
||||
nlp.to_disk(d)
|
||||
new_nlp = spacy.load(d)
|
||||
assert new_nlp.config == nlp.config
|
||||
|
||||
|
||||
def test_serialize_config_language_specific():
|
||||
"""Test that config serialization works as expected with language-specific
|
||||
factories."""
|
||||
|
|
Loading…
Reference in New Issue