def intra_ref(refs):
print("ref pairwise BLEU: %.2f" % pairwise(refs))
_ref, _hypo = [], []
for rs in refs:
for i, h in enumerate(rs):
rest = rs[:i] + rs[i+1:]
s = [sentence_bleu(r, h) for r in rest]
After Change
print("ref pairwise BLEU: %.2f" % pairwise(refs))
refs = list(zip(*refs))
m = len(refs)
concat_h = []
concat_rest = [[] for j in range(m - 1)]
for i, h in enumerate(refs):
rest = refs[:i] + refs[i+1:]
concat_h.append(h)
for j in range(m - 1):
concat_rest[j].extend(rest[j])
concat_h = list(chain.from_iterable(concat_h))bleu = corpus_bleu(concat_h, concat_rest)
print("multi-reference BLEU (leave-one-out): %.2f" % bleu)
if __name__ == "__main__":