Skip to content

Commit

Permalink
Implement replace_listeners for source in config (#7620)
Browse files Browse the repository at this point in the history
Implement replace_listeners for sourced components loaded from a config.
  • Loading branch information
adrianeboyd authored Apr 8, 2021
1 parent ee159b8 commit 82d3caf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spacy/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,16 @@ def from_config(
# 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"]
Expand Down

0 comments on commit 82d3caf

Please sign in to comment.