1earner1 commited on
Commit
0019be1
·
verified ·
1 Parent(s): 6460efa

Upload only_check_acc.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. only_check_acc.py +68 -0
only_check_acc.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tqdm import tqdm
2
+ import json
3
+ import re
4
+
5
+
6
+ dataset_file = "./llm_for_code/results/09-07-mistral_iffp_lora4_0_10000.json"
7
+
8
+
9
+ allpairs = []
10
+ with open(dataset_file, 'r') as file:
11
+ for l in file:
12
+ allpairs.append(json.loads(l))
13
+
14
+
15
+ TP = 0
16
+ TN = 0
17
+ FP = 0
18
+ FN = 0
19
+ try:
20
+ responses = []
21
+ #allpairs = allpairs[:2]
22
+ for data in tqdm(allpairs):
23
+ pair = data['progs']
24
+ #prompt = file_content + pair['prog1']['scode'] + "\nProgram 2:"
25
+ #prompt += pair['prog2']['scode']+ "\n### Response:"
26
+ result=data['response']
27
+ end_ind = result.find("###")
28
+ res = result
29
+ if end_ind>0:
30
+ res = result[:end_ind]
31
+ #print(result)
32
+ #print("$$$$")
33
+ #print(res)
34
+ ans = pair['prog1']['probid'] == pair['prog2']['probid']
35
+ correct = False
36
+ if ans:
37
+ if "Yes" in res or "yes" in res:
38
+ TP += 1
39
+ correct = True
40
+ else: #"No" in res or "no" in res:
41
+ FN += 1
42
+ #print("My Yes")
43
+ if ans == False:
44
+ if "No" in res or "no" in res:
45
+ TN += 1
46
+ correct = True
47
+ else:
48
+ FP += 1
49
+ #print("My No")
50
+
51
+ responses.append({
52
+ 'progs' : pair,
53
+ 'response': res,
54
+ 'extracted_answer': correct
55
+ })
56
+
57
+
58
+ with open(output_file, 'w+') as outfile:
59
+ for response in responses:
60
+ outfile.write(f"{json.dumps(response)}\n")
61
+
62
+
63
+ print(f"TPR: {TP/(TP+FN)}\nFPR: {TN/(TN+FP)} \nAcc: {(TN+TP)/(TP+FP+TN+FN)} ")
64
+ except Exception as e:
65
+ print(f"TPR: {TP/(TP+FN)}\nFPR: {TN/(TN+FP)} \nAcc: {(TN+TP)/(TP+FP+TN+FN)} ")
66
+ print(f"TPR: {TP/(TP+FN)}\nFPR: {TN/(TN+FP)} \nAcc: {(TN+TP)/(TP+FP+TN+FN)} ")
67
+
68
+