From e033162a1df3d843619d7ee93543a3cd6bb301e4 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 1 Nov 2017 21:49:08 +0100 Subject: [PATCH] Update tagger training example --- examples/training/train_tagger.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/training/train_tagger.py b/examples/training/train_tagger.py index 95b9efcbf..161f7910c 100644 --- a/examples/training/train_tagger.py +++ b/examples/training/train_tagger.py @@ -18,7 +18,6 @@ import random from pathlib import Path import spacy -from spacy.util import get_lang_class from spacy.tokens import Doc from spacy.gold import GoldParse @@ -52,13 +51,13 @@ def main(lang='en', output_dir=None, n_iter=25): train the tagger with a custom tag map, we're creating a new Language instance with a custom vocab. """ - lang_cls = get_lang_class(lang) # get Language class - lang_cls.Defaults.tag_map.update(TAG_MAP) # add tag map to defaults - nlp = lang_cls() # initialise Language class - + nlp = spacy.blank(lang) # add the tagger to the pipeline # nlp.create_pipe works for built-ins that are registered with spaCy tagger = nlp.create_pipe('tagger') + # Add the tags. This needs to be done before you start training. + for tag, values in TAG_MAP.items(): + tagger.add_label(tag, values) nlp.add_pipe(tagger) optimizer = nlp.begin_training()