From fd4baff475e9cb5ce24b380ec8d75ab28b48962f Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 5 Oct 2017 08:12:27 -0500 Subject: [PATCH 1/2] Update tests --- spacy/tests/lang/en/test_lemmatizer.py | 1 - spacy/tests/lang/en/test_models.py | 13 +++++++------ spacy/tests/regression/test_issue429.py | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/spacy/tests/lang/en/test_lemmatizer.py b/spacy/tests/lang/en/test_lemmatizer.py index 00f02ccb4..ecde87bed 100644 --- a/spacy/tests/lang/en/test_lemmatizer.py +++ b/spacy/tests/lang/en/test_lemmatizer.py @@ -57,7 +57,6 @@ def test_en_lemmatizer_punct(en_lemmatizer): def test_en_lemmatizer_lemma_assignment(EN): text = "Bananas in pyjamas are geese." doc = EN.make_doc(text) - EN.tensorizer(doc) assert all(t.lemma_ == '' for t in doc) EN.tagger(doc) assert all(t.lemma_ != '' for t in doc) diff --git a/spacy/tests/lang/en/test_models.py b/spacy/tests/lang/en/test_models.py index 4b1cf1f91..ab318213c 100644 --- a/spacy/tests/lang/en/test_models.py +++ b/spacy/tests/lang/en/test_models.py @@ -52,12 +52,13 @@ def test_en_models_vectors(example): # this isn't a perfect test since this could in principle fail # in a sane model as well, # but that's very unlikely and a good indicator if something is wrong - vector0 = example[0].vector - vector1 = example[1].vector - vector2 = example[2].vector - assert not numpy.array_equal(vector0,vector1) - assert not numpy.array_equal(vector0,vector2) - assert not numpy.array_equal(vector1,vector2) + if example.vocab.vectors_length: + vector0 = example[0].vector + vector1 = example[1].vector + vector2 = example[2].vector + assert not numpy.array_equal(vector0,vector1) + assert not numpy.array_equal(vector0,vector2) + assert not numpy.array_equal(vector1,vector2) @pytest.mark.xfail diff --git a/spacy/tests/regression/test_issue429.py b/spacy/tests/regression/test_issue429.py index 1baa9a1db..df8d6d3fc 100644 --- a/spacy/tests/regression/test_issue429.py +++ b/spacy/tests/regression/test_issue429.py @@ -19,7 +19,6 @@ def test_issue429(EN): matcher = Matcher(EN.vocab) matcher.add('TEST', merge_phrases, [{'ORTH': 'a'}]) doc = EN.make_doc('a b c') - EN.tensorizer(doc) EN.tagger(doc) matcher(doc) EN.entity(doc) From 5743b06e36c92fdb541c0a02d1a4b3850676418f Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 5 Oct 2017 08:12:50 -0500 Subject: [PATCH 2/2] Wrap model saving in try/except --- spacy/cli/train.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spacy/cli/train.py b/spacy/cli/train.py index a22db6abc..064f053a1 100644 --- a/spacy/cli/train.py +++ b/spacy/cli/train.py @@ -114,9 +114,12 @@ def train(cmd, lang, output_dir, train_data, dev_data, n_iter=20, n_sents=0, print_progress(i, losses, scorer.scores) finally: print("Saving model...") - with (output_path / 'model-final.pickle').open('wb') as file_: - with nlp.use_params(optimizer.averages): - dill.dump(nlp, file_, -1) + try: + with (output_path / 'model-final.pickle').open('wb') as file_: + with nlp.use_params(optimizer.averages): + dill.dump(nlp, file_, -1) + except: + print("Error saving model") def _render_parses(i, to_render):