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