michal
Update
2051b0b
import pandas as pd
from pathlib import Path
from ..styles import highlight_color
abs_path = Path(__file__).parent.parent.parent
def replace_models_names(model_name):
if "gpt" in model_name:
return model_name
replaces = {'meta-llama': 'meta_llama',
'epfl-llm':'epfl_llm',
'01-ai':'01_ai'}
new_name = model_name.replace('model-', '')
for k, v in replaces.items():
if new_name.startswith(k):
new_name = new_name.replace(k, v)
new_name = new_name.replace('-','/',1)
new_name = new_name.replace('_','-',1)
new_name = f"[{new_name}](https://huggingface.co/{new_name})"
return new_name
def load_json_data(file_path):
ALL_ACCS = pd.read_json(file_path)
for column in ALL_ACCS.columns:
if ALL_ACCS[column].apply(type).eq(dict).any():
ALL_ACCS[column] = ALL_ACCS[column].apply(str)
for column in ALL_ACCS.select_dtypes(include='number').columns:
ALL_ACCS[column] = ALL_ACCS[column].round(2)
return ALL_ACCS
file_paths = [
str(abs_path / "leaderboards/pes_accs.json"),
str(abs_path / "leaderboards/ldek_accs.json"),
str(abs_path / "leaderboards/lek_accs.json"),
]
model_data = {}
for file_path in file_paths:
ALL_ACCS = load_json_data(file_path)
for _, row in ALL_ACCS.iterrows():
model_name = replace_models_names(row["model_name"])
overall_accuracy = row["overall_accuracy"]
if model_name not in model_data:
model_data[model_name] = {"model_name": model_name}
file_key = file_path.split("/")[-1].replace(".json", "") # Use file name as key
model_data[model_name][f"overall_acc_from_{file_key}"] = overall_accuracy
ALL_ACCS = pd.DataFrame(list(model_data.values()))
ALL_ACCS=ALL_ACCS.rename(columns={'overall_acc_from_pes_accs':'PES',
'overall_acc_from_ldek_accs':'LDEK',
'overall_acc_from_lek_accs':'LEK'})
ALL_ACCS['Average'] = ALL_ACCS[['PES', 'LDEK', 'LEK']].mean(axis=1).round(2)
columns = list(ALL_ACCS.columns)
columns.insert(1, columns.pop(columns.index('Average')))
ALL_ACCS = ALL_ACCS[columns]
ALL_ACCS = ALL_ACCS.sort_values(by="Average", ascending=False)
STYLED = ALL_ACCS.style.highlight_max(
color = highlight_color,
subset=ALL_ACCS.columns[-4:]).format(precision=2)