summaryrefslogtreecommitdiff
path: root/algorithms/bleu.py
diff options
context:
space:
mode:
Diffstat (limited to 'algorithms/bleu.py')
-rwxr-xr-xalgorithms/bleu.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/algorithms/bleu.py b/algorithms/bleu.py
new file mode 100755
index 0000000..77c3c82
--- /dev/null
+++ b/algorithms/bleu.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python2
+
+import math
+
+
+def BLEU(N, w, v):
+ sum = 0
+ for i in range(N):
+ j = i+1
+ if v[i] == 0: continue
+ sum += (w[i]*math.exp(math.log(v[i])))/(2**(N-j+1))
+ print v[i], math.log(v[i]), w[i] * math.log(v[i]), w[i]
+ return sum
+
+N = 4
+w = [1.0/N for i in range(N)]
+v = [0.1, 0.1, 0.1, 0.1]
+print BLEU(N, w, v)
+