File size: 2,863 Bytes
9f50319 | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | from evaluate_code.llm_evaluator import LLMEvaluator
from datetime import datetime
from config import TASKS, MODEL_NAMES
import os
import json
import csv
def save_results(date_str,results, task_name):
"""
Save results to both JSON and CSV files
Args:
results: Dictionary containing evaluation results
task_name: Name of the task
"""
# Create results directory if it doesn't exist
if not os.path.exists("results"):
os.makedirs("results")
# Create date folder
date_path = os.path.join("results", date_str)
if not os.path.exists(date_path):
os.makedirs(date_path)
# Create task folder
task_path = os.path.join(date_path, task_name)
if not os.path.exists(task_path):
os.makedirs(task_path)
# Save JSON
json_path = os.path.join(task_path, "results.json")
with open(json_path, 'w', encoding='utf-8') as f:
json.dump(results, f, ensure_ascii=False, indent=2)
if task_name in ["S_0D", "S_1D", "S_Modification", "M_Merge", "M_Birth", "M_Filtration", "R_Selection", "R_Generation"]:
# Save CSV
csv_path = os.path.join(task_path, "results.csv")
with open(csv_path, 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
# Write header
writer.writerow(['file_name', 'accuracy'])
# Write data
for file_name, (accuracy, _) in results.items():
# Remove .parquet extension
file_name = file_name.replace('.parquet', '')
writer.writerow([file_name, accuracy])
elif task_name in ["H_Selection", "H_Generation"]:
# Save CSV
csv_path = os.path.join(task_path, "results.csv")
with open(csv_path, 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
# Write header
writer.writerow(['file_name', 'mean_rank', 'std_rank'])
# Write data
for file_name, (_, details) in results.items():
mean_rank = details['statistics']['mean_rank']
std_rank = details['statistics']['std_rank']
file_name = file_name.replace('.parquet', '')
writer.writerow([file_name, mean_rank, std_rank])
def main():
date_str = datetime.now().strftime("%Y%m%d_%H%M")
# Process each task in the task list
for task_name in TASKS:
for model_name in MODEL_NAMES:
print(f"Processing task: {task_name} with model: {model_name}")
evaluator = LLMEvaluator(
task_name=task_name,
model_name=model_name
)
# Process all graphs in all files
results = evaluator.process_dataset()
# Save results
save_results(date_str, results, task_name)
if __name__ == "__main__":
main() |