Skip to content
Branch: master
Find file Copy path
Find file Copy path
update ee9cca7 Jun 27, 2017
1 contributor

Users who have contributed to this file

37 lines (32 sloc) 1.04 KB
# coding=utf8
import os
import numpy
# ref:
def conlleval(p, g, w, filename):
p :: predictions
g :: groundtruth
w :: corresponding words
filename :: name of the file where the predictions
are written. it will be the input of script
for computing the performance in terms of precision
recall and f1 score
out = ''
for sl, sp, sw in zip(g, p, w):
out += 'BOS O O\n'
for wl, wp, w in zip(sl, sp, sw):
out += w + ' ' + wl + ' ' + wp + '\n'
out += 'EOS O O\n\n'
with open(filename, 'w') as f:
return get_metrics(filename)
def get_metrics(filename):
if os.path.exists(filename):
cmd = './ < %s | grep accuracy' % filename
out = os.popen(cmd).read().split()
os.system('rm %s' % filename)
return {'Precision': float(out[3][:-2]), 'Recall': float(out[5][:-2]), 'F1': float(out[7])}
return None
You can’t perform that action at this time.