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}")
I am getting BLEU score as 0. I think I am making mistake somwhere. But not sure where.
As suggested, use a SmoothingFunction (take a look at 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 score: 0.1379