@register_metric("bleu")
def bleu(y_true, y_predicted):
examples_len = len(y_true)
bleu_list = (sentence_bleu([y2.lower().split()], y1.lower().split())\
for y1, y2 in zip(y_true, y_predicted))
return sum(bleu_list) / examples_len if examples_len else 0.
@register_metric("per_item_bleu")
def per_item_bleu(y_true, y_predicted):
if isinstance(y_true[0], (tuple, list)):
After Change
@register_metric("bleu")
def bleu(y_true, y_predicted):
if isinstance(y_true[0], (tuple, list)):
y_true = (y[0] for y in y_true)
return corpus_bleu([[y_t.lower().split()] for y_t in y_true],
[y_p.lower().split() for y_p in y_predicted])