From 1831dbd065a8776a77d18e10b44f84c99bca4c75 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 6 Nov 2017 22:04:29 +0100 Subject: [PATCH] Add test of simple textcat workflow --- spacy/tests/textcat/test_textcat.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 spacy/tests/textcat/test_textcat.py diff --git a/spacy/tests/textcat/test_textcat.py b/spacy/tests/textcat/test_textcat.py new file mode 100644 index 000000000..772131225 --- /dev/null +++ b/spacy/tests/textcat/test_textcat.py @@ -0,0 +1,19 @@ +from __future__ import unicode_literals +from ...language import Language + +def test_simple_train(): + nlp = Language() + + nlp.add_pipe(nlp.create_pipe('textcat')) + nlp.get_pipe('textcat').add_label('is_good') + + nlp.begin_training() + + for i in range(5): + for text, answer in [('aaaa', 1.), ('bbbb', 0), ('aa', 1.), + ('bbbbbbbbb', 0.), ('aaaaaa', 1)]: + nlp.update([text], [{'cats': {'answer': answer}}]) + doc = nlp(u'aaa') + assert 'is_good' in doc.cats + assert doc.cats['is_good'] >= 0.5 +