spaCy/spacy/tests/pipeline/test_textcat.py

19 lines
563 B
Python
Raw Normal View History

2017-11-07 03:25:54 +03:00
# coding: utf8
2017-11-07 00:04:29 +03:00
from __future__ import unicode_literals
from ...language import Language
2017-11-07 03:25:54 +03:00
2017-11-07 00:04:29 +03:00
def test_simple_train():
nlp = Language()
nlp.add_pipe(nlp.create_pipe('textcat'))
2017-11-07 03:25:54 +03:00
nlp.get_pipe('textcat').add_label('answer')
2017-11-07 00:04:29 +03:00
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')
2017-11-07 03:25:54 +03:00
assert 'answer' in doc.cats
assert doc.cats['answer'] >= 0.5