From e3405f8af364778b16dba37bc53334ffe45a5d5e Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Mon, 17 Dec 2018 13:45:49 +0100 Subject: [PATCH] Don't call begin_training if updating new model (see #3059) [ci skip] --- examples/training/train_ner.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/training/train_ner.py b/examples/training/train_ner.py index 8bb01b87f..eb544bb99 100644 --- a/examples/training/train_ner.py +++ b/examples/training/train_ner.py @@ -56,7 +56,10 @@ def main(model=None, output_dir=None, n_iter=100): # get names of other pipes to disable them during training other_pipes = [pipe for pipe in nlp.pipe_names if pipe != "ner"] with nlp.disable_pipes(*other_pipes): # only train NER - optimizer = nlp.begin_training() + # reset and initialize the weights randomly – but only if we're + # training a new model + if model is None: + optimizer = nlp.begin_training() for itn in range(n_iter): random.shuffle(TRAIN_DATA) losses = {} @@ -68,7 +71,6 @@ def main(model=None, output_dir=None, n_iter=100): texts, # batch of texts annotations, # batch of annotations drop=0.5, # dropout - make it harder to memorise data - sgd=optimizer, # callable to update weights losses=losses, ) print("Losses", losses)