blob: 77c3c8258a8fa9423b9a2b7e39c1c5e059d638ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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)
|