From 82d3caf8611b60a73471c73e9b0993fea06b32cd Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Thu, 8 Apr 2021 10:21:22 +0200 Subject: [PATCH] Implement replace_listeners for source in config (#7620) Implement replace_listeners for sourced components loaded from a config. --- spacy/language.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spacy/language.py b/spacy/language.py index 04a5e843e..68bd3cd4c 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -1673,7 +1673,16 @@ class Language: # model with the same vocab as the current nlp object source_nlps[model] = util.load_model(model, vocab=nlp.vocab) source_name = pipe_cfg.get("component", pipe_name) + listeners_replaced = False + if "replace_listeners" in pipe_cfg: + for name, proc in source_nlps[model].pipeline: + if source_name in getattr(proc, "listening_components", []): + source_nlps[model].replace_listeners(name, source_name, pipe_cfg["replace_listeners"]) + listeners_replaced = True nlp.add_pipe(source_name, source=source_nlps[model], name=pipe_name) + # Delete from cache if listeners were replaced + if listeners_replaced: + del source_nlps[model] disabled_pipes = [*config["nlp"]["disabled"], *disable] nlp._disabled = set(p for p in disabled_pipes if p not in exclude) nlp.batch_size = config["nlp"]["batch_size"]