From fb48de349cd588d601d7c9bdb072f8a51a848694 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Fri, 2 Oct 2020 20:31:14 +0200 Subject: [PATCH] bwd compat for pipe.begin_training --- spacy/errors.py | 4 +++- spacy/language.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spacy/errors.py b/spacy/errors.py index dbb25479d..2c076db52 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -85,7 +85,9 @@ class Warnings: "attribute or operator.") # TODO: fix numbering after merging develop into master - W089 = ("The nlp.begin_training method has been renamed to nlp.initialize.") + W089 = ("The 'begin_training' method has been renamed to 'initialize', " + "for calls to 'nlp' as well as for the individual pipeline " + "components.") W090 = ("Could not locate any {format} files in path '{path}'.") W091 = ("Could not clean/remove the temp directory at {dir}: {msg}.") W092 = ("Ignoring annotations for sentence starts, as dependency heads are set.") diff --git a/spacy/language.py b/spacy/language.py index 14b9f4eb0..36cd251f3 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -1207,7 +1207,11 @@ class Language: ) self.tokenizer.initialize(get_examples, nlp=self, **tok_settings) for name, proc in self.pipeline: - if hasattr(proc, "initialize"): + # backwards compatibility for older components + if hasattr(proc, "begin_training"): + warnings.warn(Warnings.W089, DeprecationWarning) + proc.begin_training(get_examples, pipeline=self.pipeline, sgd=self._optimizer) + elif hasattr(proc, "initialize"): p_settings = I["components"].get(name, {}) p_settings = validate_init_settings( proc.initialize, p_settings, section="components", name=name