-
Notifications
You must be signed in to change notification settings - Fork 1
/
eval_acc.py
57 lines (48 loc) · 1.27 KB
/
eval_acc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
#evaluate the predictions, based on the reference
#arg1: predictions
#arg2: reference
#arg3: sources
#arg4: wrong predictions with references and sources
import sys
fin = open(sys.argv[1], 'r')
fref = open(sys.argv[2], 'r')
fsrc= open(sys.argv[3], 'r')
total = 0
correct = 0
predictions = []
references = []
srcs = []
for line in fin:
line = line.lower().strip()
if line != "":
predictions.append(line)
fin.close()
for line1 in fref:
line1 = line1.lower().strip()
if line1 != "":
references.append(line1)
fref.close()
for line1 in fsrc:
line1 = line1.lower().strip()
if line1 != "":
srcs.append(line1)
fsrc.close()
fres=open(sys.argv[4],'w')
for i in range (len(predictions)):
if predictions[i] != "":
total += 1
#if total == 46:
# print("#"+str(predictions[i])+"#"+str(references[i])+"#")
if predictions[i] == references[i]:
correct += 1
else:
token_src = srcs[i].replace(" ","")
token_pre = predictions[i].replace(" ","")
token_ref = references[i].replace(" ","")
fres.write(str(i)+"\t"+token_src+"\t"+token_pre+"\t"+token_ref+"\n")
#print(str(len(predictions)))
#print(str(total))
#print(str(correct))
accuracy = float(correct)/total
print(str(accuracy)+"\t"+str(correct)+"\t"+str(total))