💻 源码
from nltk.translate.bleu_score import sentence_bleu

candidate = ["it","is","a","nice","day","today"]
reference = [["today","is","a","nice","day"]]

blue1 = sentence_bleu(references=reference, hypothesis=candidate, weights=(1,))
print("blue1-->", blue1)
blue2 = sentence_bleu(references=reference, hypothesis=candidate, weights=(0.5, 0.5))
print("blue2-->", blue2)
blue3 = sentence_bleu(references=reference, hypothesis=candidate, weights=(1/3, 1/3, 1/3))
print("blue3-->", blue3)
blue4 = sentence_bleu(references=reference, hypothesis=candidate, weights=(1/4, 1/4, 1/4, 1/4))
print("blue4-->", blue4)