-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvis_bl.py
55 lines (37 loc) · 1.73 KB
/
vis_bl.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
import json
import os
from sklearn.metrics import classification_report
def cn(data):
languages = ['C', 'C#', 'C++', 'Go', 'OCaml', 'PHP', 'Python', 'Ruby', 'Rust', 'JavaScript']
for lang in languages:
lang_data = [element for element in data if element['ll2'] == lang]
view(ll2=lang, data=lang_data)
def view(ll2, data):
print(ll2)
data = [entry for entry in data if entry['output'] != '']
for item in data:
item["output"] = item['output'].split()[0].strip().replace(",", "").replace(".", "")
item["output"] = item["output"].lower().replace("no", "0").replace("yes", "1")
item["type"] = item["type"].lower().replace("nonclone", "0").replace("clone", "1")
all_true_labels = [int(item["type"]) for item in data]
all_predictions = [int(item["output"]) for item in data]
print(classification_report(all_true_labels, all_predictions, digits=2))
def main():
directory = "results/codenet"
files = os.listdir(directory)
files=[file for file in files if not (file.startswith('.') or file.startswith('~') or file.startswith('sim') or file.endswith('_xl.json')) ]
files = sorted(files)
for filename in files:
filepath = os.path.join(directory, filename)
try:
with open(filepath, "r") as file:
result = json.load(file)
print("######################", str(filename), "########################")
#To view all the results for all the LLMs
#view(ll2="none", data=result)
#View results for all the LLMs by languages
cn(result)
except Exception as e:
print(f"Error processing file {filename}: {e}")
if __name__ == "__main__":
main()