Team Ai
Apppublic

dvwn/nl2sql-api

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
taxonomy_report.py49 linesDownload Raw Back to scripts
1# Path: src/scripts/taxonomy_report.py2# Generate a taxonomy report to identify which taxonomy tags model struggles with3import json4import pandas as pd5from pathlib import Path6 7def print_taxonomyReport(results_data):8    """9    Generates and prints taxonomy breakdown.10    Accepts either a list of dictionaries (from memory) or reads from the default JSON11    """12    if not results_data:13        results_path = Path("hf_evaluation_results.json")14        if results_path.exists():15            with open(results_path, "r", encoding="utf-8") as f:16                results_data = json.load(f)17        else:18            print("No data provided and results file not found.")19            return20        21    if not results_data:22        return23    24    df = pd.DataFrame(results_data)25    df['taxonomy'] = df['taxonomy'].fillna("Unknown").astype(str)26    df['taxonomy'] = df['taxonomy'].str.split(', ')27    df_exploded = df.explode('taxonomy')28 29    # Calculate Accuract per Taxonomy Tag30    taxonomy_summary = df_exploded.groupby('taxonomy').agg(31        total_cases = ('id', 'count'),32        ex_passed = ('ex_pass', 'sum'),33        esm_passed = ('esm_pass', 'sum')34    )35 36    taxonomy_summary['ex_acc'] = (taxonomy_summary['ex_passed'] / taxonomy_summary['total_cases']) * 10037    taxonomy_summary['esm_acc'] = (taxonomy_summary['esm_passed'] / taxonomy_summary['total_cases']) * 10038 39    print("\n" + "="*50)40    print("TAXONOMY PERFORMANCE REPORT SUMMARY")41    print("-"*50)42 43    # Sort by execution accuracy44    final_report = taxonomy_summary.sort_values(by='ex_acc', ascending=False)45    print(final_report.to_string())46    47# To run the script on its own manually48if __name__ == "__main__":49    print_taxonomyReport(None)