def test_pos(model, sentences, display=False):
from sys import stdout
count = correct = 0
for sentence in sentences:
sentence = [(token[0], None) for token in sentence]
pts = model.best_path(sentence)
if display:
print sentence
print 'HMM >>>'
print pts
print model.entropy(sentences)
print '-' * 60
else:
print '\b.',
stdout.flush()
for token, tag in zip(sentence, pts):
count += 1
if tag == token[TAG]:
correct += 1
print 'accuracy over', count, 'tokens %.1f' % (100.0 * correct / count)
评论列表
文章目录