forked from TsinghuaAI/CPM-2-Finetune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval_math.py
33 lines (28 loc) · 832 Bytes
/
eval_math.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
import sys
import os
import re
folder = sys.argv[1]
filenames = os.listdir(folder)
filenames = [x for x in filenames if "0." in x]
re_exp = re.compile("[0-9\.]+%")
def repl(x):
return "({}*0.01)".format(x[0][:-1])
for filename in filenames:
try:
with open(os.path.join(folder, filename)) as fin:
cnt = 0
acc = 0
for line in fin:
exp1 = line.strip().split(" ")[0]
exp2 = " ".join(line.strip().split(" ")[1:])
exp1 = re_exp.sub(repl, exp1)
exp2 = re_exp.sub(repl, exp2)
cnt += 1
try:
if eval(exp1) == eval(exp2):
acc += 1
except:
pass
print(filename, acc/cnt)
except:
continue