Download main.py from Antislab/LLM4PH: direct link, hf CLI and curl.
- Browser
- Download file 2.86 kB
-
https://huggingface.co/datasets/Antislab/LLM4PH/resolve/main/main.py
- Command line
-
hf download hf://datasets/Antislab/LLM4PH/main.py
-
curl -L -o main.py https://huggingface.co/datasets/Antislab/LLM4PH/resolve/main/main.py
2.86 kB
| 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() |