From eb117e2fce9d1029670f52690d30d17e6edbd24e Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 2 May 2020 14:09:21 +0200 Subject: [PATCH] Add load_config_from_str helper --- spacy/util.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spacy/util.py b/spacy/util.py index ea3023629..b4ecc8b03 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -219,6 +219,23 @@ def load_config(path, create_objects=False): return config +def load_config_from_str(string, create_objects=False): + """Load a Thinc-formatted config, optionally filling in objects where + the config references registry entries. See "Thinc config files" for details. + + string (unicode or Path): Text contents of the config file. + create_objects (bool): Whether to automatically create objects when the config + references registry entries. Defaults to False. + + RETURNS (dict): The objects from the config file. + """ + config = thinc.config.Config().from_str(string) + if create_objects: + return registry.make_from_config(config, validate=True) + else: + return config + + def get_model_meta(path): """Get model meta.json from a directory path and validate its contents.