diff --git a/medcat/cat.py b/medcat/cat.py index 200ffc7b..e3f69c7f 100644 --- a/medcat/cat.py +++ b/medcat/cat.py @@ -356,6 +356,7 @@ def load_model_pack(cls, zip_path: str, meta_cat_config_dict: Optional[Dict] = None, ner_config_dict: Optional[Dict] = None, + medcat_config_dict: Optional[Dict] = None, load_meta_models: bool = True, load_addl_ner: bool = True, load_rel_models: bool = True) -> "CAT": @@ -373,6 +374,10 @@ def load_model_pack(cls, A config dict that will overwrite existing configs in transformers ner. e.g. ner_config_dict = {'general': {'chunking_overlap_window': 6}. Defaults to None. + medcat_config_dict (Optional[Dict]): + A config dict that will overwrite existing configs in the main medcat config + before pipe initialisation. This can be useful if wanting to change something + that only takes effect at init time (e.g spacy model). Defaults to None. load_meta_models (bool): Whether to load MetaCAT models if present (Default value True). load_addl_ner (bool): @@ -395,7 +400,7 @@ def load_model_pack(cls, # load config config_path = os.path.join(model_pack_path, "config.json") - cdb.load_config(config_path) + cdb.load_config(config_path, medcat_config_dict) # TODO load addl_ner diff --git a/medcat/cdb.py b/medcat/cdb.py index e6384336..89fd3d8e 100644 --- a/medcat/cdb.py +++ b/medcat/cdb.py @@ -515,7 +515,17 @@ async def save_async(self, path: str) -> None: } await f.write(dill.dumps(to_save)) - def load_config(self, config_path: str) -> None: + def load_config(self, config_path: str, config_dict: Optional[Dict] = None) -> None: + """Load the config from disk. + + Args: + config_path (str): The path to the config file. + config_dict (Optional[Dict]): A config to merge with. + + Raises: + ValueError: If a config was not found in CDB nor as a separate json. + Or if a config was found both in CDB as well as a separate json. + """ if not os.path.exists(config_path): if not self._config_from_file: # if there's no config defined anywhere @@ -544,6 +554,8 @@ def load_config(self, config_path: str) -> None: # new config, potentially new weighted_average_function to read self._init_waf_from_config() # mark config read from file + if config_dict: + self.config.merge_config(config_dict) self._config_from_file = True @classmethod