prediction = "I am ABC. I have completed my bachelor's degree in computer application at XYZ University and I am currently pursuing my master's degree in computer application through distance education."
reference = "I'm ABC. I have finished my four-year certification in PC application at XYZ and I'm currently pursuing my graduate degree in PC application through distance training."
from nltk.translate.bleu_score import sentence_bleu
# Tokenize the sentences
prediction_tokens = prediction.split()
reference_tokens = reference.split()
# Calculate BLEU score
bleu_score = sentence_bleu([reference_tokens], prediction_tokens)
# Print the BLEU score
print(f"BLEU score: {bleu_score:.4f}")
我的 BLEU 分数为 0。我认为我在某个地方犯了错误。但不知道在哪里。
按照建议,使用 SmoothingFunction (看看 https://github.com/nltk/nltk/issues/1554)
prediction = "I am ABC. I have completed my bachelor's degree in computer application at XYZ University and I am currently pursuing my master's degree in computer application through distance education."
reference = "I'm ABC. I have finished my four-year certification in PC application at XYZ and I'm currently pursuing my graduate degree in PC application through distance training."
from nltk.translate.bleu_score import sentence_bleu
from nltk.translate.bleu_score import SmoothingFunction
# Tokenize the sentences
prediction_tokens = prediction.split()
reference_tokens = reference.split()
# Calculate BLEU score
bleu_score = sentence_bleu([reference_tokens], prediction_tokens, smoothing_function=SmoothingFunction().method4)
# Print the BLEU score
print(f"BLEU score: {bleu_score:.4f}")
BLEU 分数:0.1379