Skip to content

Instantly share code, notes, and snippets.

@felipessalvatore
Created June 23, 2018 21:08
Show Gist options
  • Save felipessalvatore/ea5be8069c48c817bae675b31cd0c76b to your computer and use it in GitHub Desktop.
Save felipessalvatore/ea5be8069c48c817bae675b31cd0c76b to your computer and use it in GitHub Desktop.
from nltk.translate.bleu_score import sentence_bleu, brevity_penalty, SmoothingFunction
reference = [ "In the farm's afternoons there is too much blue".split(" ") ]
candidate = "In the afternoons of the farm there is too much blue".split(" ")
score = sentence_bleu(reference, candidate)
print("candidate1")
print(score)
print(len(reference[0]), len(candidate))
print("BP = {}".format(brevity_penalty(len(reference[0]), len(candidate))))
candidate = "In the farm's afternoons there is a lot of blue".split(" ")
score = sentence_bleu(reference, candidate)
print("candidate2")
print(score)
print(len(reference[0]), len(candidate))
print("BP = {}".format(brevity_penalty(len(reference[0]), len(candidate))))
candidate = "The farm's afternoons are blue".split(" ")
score = sentence_bleu(reference, candidate)
print("candidate3")
print(score)
print(len(reference[0]), len(candidate))
print("BP = {}".format(brevity_penalty(len(reference[0]), len(candidate))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment