def gleu(self, stats, smooth=False):
"""Compute GLEU from collected statistics obtained by call(s) to gleu_stats"""
# smooth 0 counts for sentence-level scores
if smooth:
stats = [s if s != 0 else 1 for s in stats]
if len(filter(lambda x: x == 0, stats)) > 0:
return 0
(c, r) = stats[:2]
log_gleu_prec = sum([math.log(float(x) / y)
for x, y in zip(stats[2::2], stats[3::2])]) / 4
for i, (x, y) in enumerate(zip(stats[2::2], stats[3::2])) :
pass
#print 'Precision', i+1, '=', x, '/', y, '=', 1.*x/y
# log_gleu_prec = sum([math.log(float(x) / y)
# for x, y in zip(stats[2::2], stats[3::2])]) / 4
return math.exp(min([0, 1 - float(r) / c]) + log_gleu_prec)
评论列表
文章目录