Skip to content

Instantly share code, notes, and snippets.

@rmeertens
Created March 24, 2017 08:35
Show Gist options
  • Save rmeertens/fcd35f62696172aefcfd28094d9afabc to your computer and use it in GitHub Desktop.
Save rmeertens/fcd35f62696172aefcfd28094d9afabc to your computer and use it in GitHub Desktop.
I wanted to know more about the BLEU score, so did this experiment:
import nltk
reference = "today I go cycling".split()
references = [reference]
hypothesis_strings = ["today I go cycling",
"today I go biking",
"today , I go cycling",
"today I go ride my bike",
"today I go bicycles",
"today I go fietsen",
"today I go refrigerator"]
longest_sentence_length = max([len(s) for s in hypothesis_strings])
for hypothesis in hypothesis_strings:
bluescore = nltk.translate.bleu_score.sentence_bleu(references,hypothesis.split())
print("%s %f" % (hypothesis.ljust(longest_sentence_length), bluescore))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment