From 573f5c863fc075b698d2bedb63707050ca4e18b7 Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Tue, 24 Nov 2020 13:13:16 +0100 Subject: [PATCH] Fix tag map clobbering in spacy train (#6437) Fix bug from #5768 where the tag map is clobbered if a custom tag map isn't provided. --- spacy/cli/train.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spacy/cli/train.py b/spacy/cli/train.py index 0a640d909..19880295a 100644 --- a/spacy/cli/train.py +++ b/spacy/cli/train.py @@ -137,9 +137,6 @@ def train( output_path.mkdir() msg.good("Created output directory: {}".format(output_path)) - tag_map = {} - if tag_map_path is not None: - tag_map = srsly.read_json(tag_map_path) # Take dropout and batch size as generators of values -- dropout # starts high and decays sharply, to force the optimizer to explore. # Batch size starts at 1 and grows, so that we make updates quickly @@ -250,8 +247,10 @@ def train( pipe_cfg = {} nlp.add_pipe(nlp.create_pipe(pipe, config=pipe_cfg)) - # Replace tag map with provided mapping - nlp.vocab.morphology.load_tag_map(tag_map) + if tag_map_path is not None: + tag_map = srsly.read_json(tag_map_path) + # Replace tag map with provided mapping + nlp.vocab.morphology.load_tag_map(tag_map) # Create empty extra lexeme tables so the data from spacy-lookups-data # isn't loaded if these features are accessed