-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_math_rule.py
More file actions
56 lines (49 loc) · 1.65 KB
/
Copy pathtest_math_rule.py
File metadata and controls
56 lines (49 loc) · 1.65 KB
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
import json
import re
def test(files):
for file in files:
cnt = 0
sum = 0
with open(file,"r",encoding="utf-8") as fr:
data = json.load(fr)
for line in data:
# s = line["Judge"]
s = line["output"]
last = s.split("\n\n")[-1]
ans = line["answer"]
line["last"] = last
flag = False
try:
float(ans)
# cnt += 1
numbers = re.findall(r"[-+]?\d*\.\d+|[-+]?\d+", last)
sum += 1
# if ans in last:
# cnt += 1
# if numbers[-1]
if numbers:
line["sample"] = numbers[-1]
if numbers[-1] == ans:
cnt += 1
flag = True
except:
# pass
if ans in last:
cnt += 1
flag = True
line["rule_judge"] = flag
# with open(file,"w") as fw:
# json.dump(data, fw, ensure_ascii=False,indent=4)
print(f"file:{file} acc:{cnt / len(data) }")
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--files",nargs="+",action="store",type=str)
# parser.add_argument("--path",default=None,type=str)
# parser.add_argument("--num_gpus",default=1,type=int)
# parser.add_argument("--stop_tokens",nargs='+',action="store",type=str)
# parser.add_argument("--batch_size",type=int,default=32)
# parser.add_argument("--stop_token_ids",nargs='+',type=int,action="store")
args = parser.parse_args()
files = args.files
test(files)