|
| 1 | +import json |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import argparse |
| 5 | +import logging |
| 6 | +from pathlib import Path |
| 7 | +from typing import Optional |
| 8 | + |
| 9 | +import pandas as pd |
| 10 | +import seaborn as sns |
| 11 | +import matplotlib.pyplot as plt |
| 12 | +from huggingface_hub import snapshot_download |
| 13 | +import datasets |
| 14 | +import json |
| 15 | + |
| 16 | +import numpy as np |
| 17 | +import matplotlib.pyplot as plt |
| 18 | +from itertools import combinations |
| 19 | +from collections import defaultdict |
| 20 | + |
| 21 | + |
| 22 | +FONT_SIZES = {"small": 12, "medium": 16, "large": 18} |
| 23 | + |
| 24 | +PLOT_PARAMS = { |
| 25 | + "font.family": "serif", |
| 26 | + "font.serif": ["Times New Roman", "STIX"], |
| 27 | + "font.size": FONT_SIZES.get("medium"), |
| 28 | + "axes.titlesize": FONT_SIZES.get("large"), |
| 29 | + "axes.labelsize": FONT_SIZES.get("large"), |
| 30 | + "xtick.labelsize": FONT_SIZES.get("large"), |
| 31 | + "ytick.labelsize": FONT_SIZES.get("small"), |
| 32 | + "legend.fontsize": FONT_SIZES.get("medium"), |
| 33 | + "figure.titlesize": FONT_SIZES.get("medium"), |
| 34 | + "text.usetex": False, |
| 35 | +} |
| 36 | + |
| 37 | +logging.basicConfig(level=logging.INFO) |
| 38 | + |
| 39 | +plt.rcParams.update(PLOT_PARAMS) |
| 40 | + |
| 41 | +def load_json(json_file_path): |
| 42 | + with open(json_file_path, "r") as file: |
| 43 | + json_data = json.load(file) |
| 44 | + return json_data |
| 45 | + |
| 46 | +results_dir = 'data/eval-results-maple' |
| 47 | +results_path = Path(results_dir) |
| 48 | + |
| 49 | +results_all = [] |
| 50 | +for result_file in results_path.glob("*.json"): |
| 51 | + raw_results = load_json(result_file) |
| 52 | + if "leaderboard" in raw_results.keys(): |
| 53 | + model_id = raw_results["model"] |
| 54 | + subset_results = raw_results['subset'] |
| 55 | + overall = raw_results['scores']['accuracy'] |
| 56 | + remove_key = ['model', 'model_type', 'chat_template'] |
| 57 | + for key in remove_key: |
| 58 | + del subset_results[key] |
| 59 | + elif "subset_results" in raw_results.keys(): |
| 60 | + model_id = raw_results["model"] |
| 61 | + subset_results = raw_results['subset_results'] |
| 62 | + overall = raw_results['accuracy'] |
| 63 | + else: |
| 64 | + model_id = raw_results["model"] |
| 65 | + subset_results = raw_results['extra_results'] |
| 66 | + overall = raw_results['accuracy'] |
| 67 | + # print(model_id, overall) |
| 68 | + # print("\t", subset_results) |
| 69 | + # results_all.append([model_id, overall, subset_results]) |
| 70 | + results_all.append({'Model': model_id, 'Avg': overall, **subset_results}) |
| 71 | + |
| 72 | + # import ipdb; ipdb.set_trace() |
| 73 | + |
| 74 | +TOP = 10 |
| 75 | +# results_all.sort(key=lambda x: x[1], reverse=True) |
| 76 | +# results_all = results_all[:TOP] |
| 77 | +# print(results_all) |
| 78 | + |
| 79 | +df_results = pd.DataFrame(results_all) |
| 80 | +df_results = df_results.sort_values(by='Avg', ascending=False).reset_index(drop=True) |
| 81 | +df_results = df_results.head(10).reset_index(drop=True) |
| 82 | + |
| 83 | +df_results.columns = df_results.columns.str.replace('^maple-', '', regex=True) |
| 84 | +df_results = df_results.set_index("Model") |
| 85 | +df_results = df_results * 100 |
| 86 | +fig, ax = plt.subplots(1, 1, figsize=(18, 5)) |
| 87 | + |
| 88 | +sns.heatmap(df_results, ax=ax, cmap="YlGn", annot=True, annot_kws={"size": 16}, |
| 89 | + fmt=".1f", cbar=False) |
| 90 | + |
| 91 | +ax.xaxis.set_ticks_position("top") |
| 92 | +ax.tick_params(axis="x", labelrotation=45) |
| 93 | +ax.set_ylabel("") |
| 94 | +ax.set_yticklabels([f"{model} " for model in df_results.index]) |
| 95 | + |
| 96 | +plt.tight_layout() |
| 97 | + |
| 98 | +plt.savefig("plots/maple.pdf", bbox_inches="tight") |
| 99 | +# import ipdb; ipdb.set_trace() |
| 100 | + |
| 101 | + |
0 commit comments