From c8a12c5d85c65b9bde62d87976eaf4fb7c2352ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danie=CC=88l=20de=20Kok?= Date: Fri, 24 Jun 2022 10:18:00 +0200 Subject: [PATCH] Extend tagger and senter tests So that they, like the other tests, also check that we get no activations if no activations were requested. --- spacy/tests/pipeline/test_senter.py | 6 +++++- spacy/tests/pipeline/test_tagger.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spacy/tests/pipeline/test_senter.py b/spacy/tests/pipeline/test_senter.py index cd194115f..db8d220bd 100644 --- a/spacy/tests/pipeline/test_senter.py +++ b/spacy/tests/pipeline/test_senter.py @@ -115,12 +115,16 @@ def test_store_activations(): train_examples.append(Example.from_dict(nlp.make_doc(t[0]), t[1])) nlp.initialize(get_examples=lambda: train_examples) + nO = senter.model.get_dim("nO") + + doc = nlp("This is a test.") + assert len(list(doc.activations["senter"].keys())) == 0 senter.store_activations = True doc = nlp("This is a test.") assert "senter" in doc.activations assert set(doc.activations["senter"].keys()) == {"guesses", "probs"} - assert doc.activations["senter"]["probs"].shape == (5, 2) + assert doc.activations["senter"]["probs"].shape == (5, nO) assert doc.activations["senter"]["guesses"].shape == (5,) senter.store_activations = ["probs"] diff --git a/spacy/tests/pipeline/test_tagger.py b/spacy/tests/pipeline/test_tagger.py index ac1050f48..e1aef969a 100644 --- a/spacy/tests/pipeline/test_tagger.py +++ b/spacy/tests/pipeline/test_tagger.py @@ -222,6 +222,9 @@ def test_store_activations(): train_examples.append(Example.from_dict(nlp.make_doc(t[0]), t[1])) nlp.initialize(get_examples=lambda: train_examples) + doc = nlp("This is a test.") + assert len(list(doc.activations["tagger"].keys())) == 0 + tagger.store_activations = True doc = nlp("This is a test.") assert "tagger" in doc.activations