From bfe17b7df1192238b8c122cfd3b2c74bca9d0249 Mon Sep 17 00:00:00 2001 From: ines Date: Wed, 1 Nov 2017 13:14:31 +0100 Subject: [PATCH] Fix begin_training if get_gold_tuples is None --- examples/training/train_intent_parser.py | 2 +- examples/training/train_new_entity_type.py | 2 +- examples/training/train_parser.py | 2 +- examples/training/train_tagger.py | 2 +- examples/training/train_textcat.py | 2 +- spacy/language.py | 4 +++- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/training/train_intent_parser.py b/examples/training/train_intent_parser.py index def0ed370..b51a4a10c 100644 --- a/examples/training/train_intent_parser.py +++ b/examples/training/train_intent_parser.py @@ -94,7 +94,7 @@ def main(model=None, output_dir=None, n_iter=100): other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'parser'] with nlp.disable_pipes(*other_pipes): # only train parser - optimizer = nlp.begin_training(lambda: []) + optimizer = nlp.begin_training() for itn in range(n_iter): random.shuffle(TRAIN_DATA) losses = {} diff --git a/examples/training/train_new_entity_type.py b/examples/training/train_new_entity_type.py index 1c70f7c03..062191440 100644 --- a/examples/training/train_new_entity_type.py +++ b/examples/training/train_new_entity_type.py @@ -87,7 +87,7 @@ def main(model=None, new_model_name='animal', output_dir=None, n_iter=50): other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'ner'] with nlp.disable_pipes(*other_pipes): # only train NER random.seed(0) - optimizer = nlp.begin_training(lambda: []) + optimizer = nlp.begin_training() for itn in range(n_iter): losses = {} gold_parses = get_gold_parses(nlp.make_doc, TRAIN_DATA) diff --git a/examples/training/train_parser.py b/examples/training/train_parser.py index e321fdb1e..9e1d10414 100644 --- a/examples/training/train_parser.py +++ b/examples/training/train_parser.py @@ -64,7 +64,7 @@ def main(model=None, output_dir=None, n_iter=1000): # get names of other pipes to disable them during training other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'parser'] with nlp.disable_pipes(*other_pipes): # only train parser - optimizer = nlp.begin_training(lambda: []) + optimizer = nlp.begin_training() for itn in range(n_iter): random.shuffle(TRAIN_DATA) losses = {} diff --git a/examples/training/train_tagger.py b/examples/training/train_tagger.py index 7508c2e66..95b9efcbf 100644 --- a/examples/training/train_tagger.py +++ b/examples/training/train_tagger.py @@ -61,7 +61,7 @@ def main(lang='en', output_dir=None, n_iter=25): tagger = nlp.create_pipe('tagger') nlp.add_pipe(tagger) - optimizer = nlp.begin_training(lambda: []) + optimizer = nlp.begin_training() for i in range(n_iter): random.shuffle(TRAIN_DATA) losses = {} diff --git a/examples/training/train_textcat.py b/examples/training/train_textcat.py index fc9610a66..852635075 100644 --- a/examples/training/train_textcat.py +++ b/examples/training/train_textcat.py @@ -59,7 +59,7 @@ def main(model=None, output_dir=None, n_iter=20): # get names of other pipes to disable them during training other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'textcat'] with nlp.disable_pipes(*other_pipes): # only train textcat - optimizer = nlp.begin_training(lambda: []) + optimizer = nlp.begin_training() print("Training the model...") print('{:^5}\t{:^5}\t{:^5}\t{:^5}'.format('LOSS', 'P', 'R', 'F')) for i in range(n_iter): diff --git a/spacy/language.py b/spacy/language.py index 806172f36..01ffd07bf 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -436,8 +436,10 @@ class Language(object): **cfg: Config parameters. RETURNS: An optimizer """ + if get_gold_tuples is None: + get_gold_tuples = lambda: [] # Populate vocab - if get_gold_tuples is not None: + else: for _, annots_brackets in get_gold_tuples(): for annots, _ in annots_brackets: for word in annots[1]: