-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathse.py
53 lines (41 loc) · 1.93 KB
/
se.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
import json
from tqdm import tqdm
import time
from gpt_inf_se import se, se_inte, se_reas, se_sl
def main():
total_inference_time = 0.0
with open("data/java_xl.json", "r") as file:
data = json.load(file)
with open("last/sim_java_xl_v.json", "r") as file:
data_sim = json.load(file)
code_explanation_expert = {
"role": "system",
"content": "You are an expert in code clone detection"
}
for i in tqdm(range(len(data)), desc="data processing"):
inference_start_time = time.time()
success = False
while not success:
try:
codeA = data[i]['codeA']
codeB = data[i]['codeB']
data[i]['sim'] = data_sim[i]['output']
data[i]['inte'] = se_inte(codeA= codeA, codeB=codeB, context=code_explanation_expert)
data[i]['reas'] = se_reas(codeA= codeA, codeB=codeB, context=code_explanation_expert)
data[i]['sl'] = se_sl(codeA= codeA, codeB=codeB, context=code_explanation_expert)
data[i]['result'] = se(sim_= data[i]['sim'], reas_= data[i]['reas'], sl_= data[i]['sl'], inte_= data[i]['inte'], context=code_explanation_expert)
with open(f"tmp/se_java_xl.json", 'w') as tp_file:
json.dump(data, tp_file, indent=4)
success = True
inference_time = time.time() - inference_start_time
total_inference_time += inference_time
except Exception as e:
time.sleep(30)
print(f"Error processing index {i}: {e}")
with open(f'error/e{i}.json', 'w') as err:
json.dump(data, err, indent=4)
with open('results/se_java_xl.json', 'w') as fichier_sortie:
json.dump(data, fichier_sortie, indent=4)
print(f"Average Inference Time: {total_inference_time} seconds")
if __name__ == "__main__":
main()