Skip to content

Instantly share code, notes, and snippets.

@prakhar21
Last active December 25, 2017 08:13
Show Gist options
  • Save prakhar21/bbfc1e08b4cfc62329a77e719ae920c9 to your computer and use it in GitHub Desktop.
Save prakhar21/bbfc1e08b4cfc62329a77e719ae920c9 to your computer and use it in GitHub Desktop.
BLEU Score calculation
#!/usr/bin/env python
from nltk.translate.bleu_score import sentence_bleu
def perfect():
machine_translation = "this blog talks about scoring machine translated text"
machine_trans = machine_translation.split()
reference_translation = "this blog talks about scoring machine translated text"
reference_trans = [reference_translation.split()]
score = sentence_bleu(reference_trans,machine_trans)
return score
def imperfect():
machine_translation = "the quick brown fox"
machine_trans = machine_translation.split()
reference_translation = "this blog talks about scoring machine translated text"
reference_trans = [reference_translation.split()]
score = sentence_bleu(reference_trans,machine_trans)
return score
if __name__ == '__main__':
print perfect()
print imperfect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment