-
Notifications
You must be signed in to change notification settings - Fork 7
/
leaderboard.py
165 lines (149 loc) Β· 6.23 KB
/
leaderboard.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import pickle
import gradio as gr
import numpy as np
import pandas as pd
leader_component_values = [None] * 5
TASK_TYPE_TO_EMOJI = {
"Retrieval": "π",
"Clustering": "β¨",
"STS": "βοΈ",
}
def make_arena_leaderboard_md(elo_results):
arena_df = elo_results["leaderboard_table_df"]
last_updated = elo_results["last_updated_datetime"]
total_votes = sum(arena_df["num_battles"]) // 2
total_models = len(arena_df)
leaderboard_md = f"""
Total #models: **{total_models}**. Total #votes: **{total_votes}**. Only anonymous votes count. Last updated: {last_updated}.
Contribute your votes π³οΈ at [MTEB Arena](https://huggingface.co/spaces/mteb/arena)! **Rank** is only based on the MTEB Arena Elo. The MTEB Avg scores are just displayed for information and taken from the [MTEB LB](https://hf.co/spaces/mteb/leaderboard).
"""
return leaderboard_md
def model_hyperlink(model_name, link):
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
def load_leaderboard_table_csv(filename, add_hyperlink=True):
df = pd.read_csv(filename)
for col in df.columns:
if "Arena Elo rating" in col:
df[col] = df[col].apply(lambda x: int(x) if x != "-" else np.nan)
elif col in ("MTEB Overall Avg", "MTEB Retrieval Avg", "MTEB Clustering Avg", "MTEB STS Avg"):
df[col] = df[col].apply(lambda x: x if x != "-" else np.nan)
if add_hyperlink and col == "Model":
df[col] = df.apply(lambda row: model_hyperlink(row[col], row["Link"]), axis=1)
return df
def get_arena_table(arena_df, model_table_df, task_type="Retrieval"):
# sort by rating
arena_df = arena_df.sort_values(by=["rating"], ascending=False)
values = []
for i in range(len(arena_df)):
row = []
model_key = arena_df.index[i]
model_name = model_table_df[model_table_df["key"] == model_key]["Model"].values[0]
# rank
row.append(i + 1)
# model display name
row.append(model_name)
# elo rating
row.append(round(arena_df.iloc[i]["rating"]))
upper_diff = round(arena_df.iloc[i]["rating_q975"] - arena_df.iloc[i]["rating"])
lower_diff = round(arena_df.iloc[i]["rating"] - arena_df.iloc[i]["rating_q025"])
row.append(f"+{upper_diff}/-{lower_diff}")
# num battles
row.append(round(arena_df.iloc[i]["num_battles"]))
row.append(model_table_df.iloc[i]["MTEB Overall Avg"])
row.append(model_table_df.iloc[i][f"MTEB {task_type} Avg"])
# Organization
row.append(
model_table_df[model_table_df["key"] == model_key]["Organization"].values[0]
)
# license
row.append(
model_table_df[model_table_df["key"] == model_key]["License"].values[0]
)
values.append(row)
return values
def build_leaderboard_tab(elo_results_file, leaderboard_table_file, show_plot=False, task_type="Retrieval"):
if elo_results_file is None: # Do live update
md = "Loading ..."
p1 = p2 = p3 = p4 = None
else:
with open(elo_results_file, "rb") as fin:
elo_results = pickle.load(fin)
anony_elo_results = elo_results["anony"]
anony_arena_df = anony_elo_results["leaderboard_table_df"]
p1 = anony_elo_results["win_fraction_heatmap"]
p2 = anony_elo_results["battle_count_heatmap"]
p3 = anony_elo_results["bootstrap_elo_rating"]
p4 = anony_elo_results["average_win_rate_bar"]
md = f"""
# π MTEB Arena Leaderboard: {task_type} {TASK_TYPE_TO_EMOJI[task_type]}
"""
# | [GitHub](https://github.com/embeddings-benchmark) |
md_1 = gr.Markdown(md, elem_id="leaderboard_markdown")
if leaderboard_table_file:
model_table_df = load_leaderboard_table_csv(leaderboard_table_file)
arena_table_vals = get_arena_table(anony_arena_df, model_table_df, task_type=task_type)
md = make_arena_leaderboard_md(anony_elo_results)
gr.Markdown(md, elem_id="leaderboard_markdown")
gr.Dataframe(
headers=[
"Rank",
"π€ Model",
"β MTEB Arena Elo",
"π 95% CI",
"π³οΈ Votes",
"π₯ MTEB Overall Avg",
f"π₯ MTEB {task_type} Avg",
"Organization",
"License",
],
datatype=[
"str",
"markdown",
"number",
"str",
"number",
"number",
"number",
"str",
"str",
],
value=arena_table_vals,
elem_id="arena_leaderboard_dataframe",
height=700,
column_widths=[50, 150, 100, 100, 100, 100, 100, 150, 150],
wrap=True,
)
if not show_plot:
gr.Markdown(
"""## We are still collecting more votes on more models. The ranking will be updated very frequently. Please stay tuned!""",
elem_id="leaderboard_markdown",
)
else:
pass
leader_component_values[:] = [md, p1, p2, p3, p4]
"""
with gr.Row():
with gr.Column():
gr.Markdown(
"#### Figure 1: Fraction of Model A Wins for All Non-tied A vs. B Battles"
)
plot_1 = gr.Plot(p1, show_label=False)
with gr.Column():
gr.Markdown(
"#### Figure 2: Battle Count for Each Combination of Models (without Ties)"
)
plot_2 = gr.Plot(p2, show_label=False)
with gr.Row():
with gr.Column():
gr.Markdown(
"#### Figure 3: Bootstrap of Elo Estimates (1000 Rounds of Random Sampling)"
)
plot_3 = gr.Plot(p3, show_label=False)
with gr.Column():
gr.Markdown(
"#### Figure 4: Average Win Rate Against All Other Models (Assuming Uniform Sampling and No Ties)"
)
plot_4 = gr.Plot(p4, show_label=False)
"""
# return [md_1, plot_1, plot_2, plot_3, plot_4]
return [md_1]