Lisa Dunlap
commited on
Commit
β’
576afc5
1
Parent(s):
80bb49b
mirror fschat repo
Browse files- app.py +30 -676
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,692 +1,45 @@
|
|
1 |
-
|
2 |
-
import
|
|
|
3 |
import argparse
|
4 |
import glob
|
5 |
-
import pickle
|
6 |
-
|
7 |
-
import gradio as gr
|
8 |
-
import numpy as np
|
9 |
-
import pandas as pd
|
10 |
import re
|
11 |
-
|
12 |
-
# notebook_url = "https://colab.research.google.com/drive/1RAWb22-PFNI-X1gPVzc927SGUdfr6nsR?usp=sharing"
|
13 |
-
notebook_url = "https://colab.research.google.com/drive/1KdwokPjirkTmpO_P1WByFNFiqxWQquwH#scrollTo=o_CpbkGEbhrK"
|
14 |
-
|
15 |
-
basic_component_values = [None] * 6
|
16 |
-
leader_component_values = [None] * 5
|
17 |
-
|
18 |
-
|
19 |
-
def make_default_md(arena_df, elo_results):
|
20 |
-
total_votes = sum(arena_df["num_battles"]) // 2
|
21 |
-
total_models = len(arena_df)
|
22 |
-
|
23 |
-
leaderboard_md = f"""
|
24 |
-
# π LMSYS Chatbot Arena Leaderboard
|
25 |
-
| [Vote](https://chat.lmsys.org) | [Blog](https://lmsys.org/blog/2023-05-03-arena/) | [GitHub](https://github.com/lm-sys/FastChat) | [Paper](https://arxiv.org/abs/2306.05685) | [Dataset](https://github.com/lm-sys/FastChat/blob/main/docs/dataset_release.md) | [Twitter](https://twitter.com/lmsysorg) | [Discord](https://discord.gg/HSWAKCrnFx) |
|
26 |
-
|
27 |
-
### **This is a mirror of the leaderboard on the LMSys website. Go to [lmsys.org](https://lmsys.org) to vote!**
|
28 |
-
LMSYS [Chatbot Arena](https://lmsys.org/blog/2023-05-03-arena/) is a crowdsourced open platform for LLM evals.
|
29 |
-
We've collected over **500,000** human preference votes to rank LLMs with the Elo ranking system.
|
30 |
-
"""
|
31 |
-
return leaderboard_md
|
32 |
-
|
33 |
-
|
34 |
-
def make_arena_leaderboard_md(arena_df):
|
35 |
-
total_votes = sum(arena_df["num_battles"]) // 2
|
36 |
-
total_models = len(arena_df)
|
37 |
-
space = " "
|
38 |
-
leaderboard_md = f"""
|
39 |
-
Total #models: **{total_models}**.{space} Total #votes: **{"{:,}".format(total_votes)}**.{space} Last updated: April 11, 2024.
|
40 |
-
|
41 |
-
π£ **NEW!** View leaderboard for different categories (e.g., coding, long user query)!
|
42 |
-
|
43 |
-
Code to recreate leaderboard tables and plots in this [notebook]({notebook_url}). Cast your vote π³οΈ at [chat.lmsys.org](https://chat.lmsys.org)!
|
44 |
-
"""
|
45 |
-
return leaderboard_md
|
46 |
-
|
47 |
-
def make_category_arena_leaderboard_md(arena_df, arena_subset_df, name="Overall"):
|
48 |
-
total_votes = sum(arena_df["num_battles"]) // 2
|
49 |
-
total_models = len(arena_df)
|
50 |
-
space = " "
|
51 |
-
total_subset_votes = sum(arena_subset_df["num_battles"]) // 2
|
52 |
-
total_subset_models = len(arena_subset_df)
|
53 |
-
leaderboard_md = f"""### {cat_name_to_explanation[name]}
|
54 |
-
#### [Coverage] {space} #models: **{total_subset_models} ({round(total_subset_models/total_models *100)}%)** {space} #votes: **{"{:,}".format(total_subset_votes)} ({round(total_subset_votes/total_votes * 100)}%)**{space}
|
55 |
-
"""
|
56 |
-
return leaderboard_md
|
57 |
-
|
58 |
-
def make_full_leaderboard_md(elo_results):
|
59 |
-
leaderboard_md = f"""
|
60 |
-
Three benchmarks are displayed: **Arena Elo**, **MT-Bench** and **MMLU**.
|
61 |
-
- [Chatbot Arena](https://chat.lmsys.org/?arena) - a crowdsourced, randomized battle platform. We use 500K+ user votes to compute Elo ratings.
|
62 |
-
- [MT-Bench](https://arxiv.org/abs/2306.05685): a set of challenging multi-turn questions. We use GPT-4 to grade the model responses.
|
63 |
-
- [MMLU](https://arxiv.org/abs/2009.03300) (5-shot): a test to measure a model's multitask accuracy on 57 tasks.
|
64 |
-
|
65 |
-
π» Code: The MT-bench scores (single-answer grading on a scale of 10) are computed by [fastchat.llm_judge](https://github.com/lm-sys/FastChat/tree/main/fastchat/llm_judge).
|
66 |
-
The MMLU scores are mostly computed by [InstructEval](https://github.com/declare-lab/instruct-eval).
|
67 |
-
Higher values are better for all benchmarks. Empty cells mean not available.
|
68 |
-
"""
|
69 |
-
return leaderboard_md
|
70 |
-
|
71 |
-
|
72 |
-
def make_leaderboard_md_live(elo_results):
|
73 |
-
leaderboard_md = f"""
|
74 |
-
# Leaderboard
|
75 |
-
Last updated: {elo_results["last_updated_datetime"]}
|
76 |
-
{elo_results["leaderboard_table"]}
|
77 |
-
"""
|
78 |
-
return leaderboard_md
|
79 |
-
|
80 |
-
|
81 |
-
def update_elo_components(max_num_files, elo_results_file):
|
82 |
-
log_files = get_log_files(max_num_files)
|
83 |
-
|
84 |
-
# Leaderboard
|
85 |
-
if elo_results_file is None: # Do live update
|
86 |
-
battles = clean_battle_data(log_files)
|
87 |
-
elo_results = report_elo_analysis_results(battles)
|
88 |
-
|
89 |
-
leader_component_values[0] = make_leaderboard_md_live(elo_results)
|
90 |
-
leader_component_values[1] = elo_results["win_fraction_heatmap"]
|
91 |
-
leader_component_values[2] = elo_results["battle_count_heatmap"]
|
92 |
-
leader_component_values[3] = elo_results["bootstrap_elo_rating"]
|
93 |
-
leader_component_values[4] = elo_results["average_win_rate_bar"]
|
94 |
-
|
95 |
-
# Basic stats
|
96 |
-
basic_stats = report_basic_stats(log_files)
|
97 |
-
md0 = f"Last updated: {basic_stats['last_updated_datetime']}"
|
98 |
-
|
99 |
-
md1 = "### Action Histogram\n"
|
100 |
-
md1 += basic_stats["action_hist_md"] + "\n"
|
101 |
-
|
102 |
-
md2 = "### Anony. Vote Histogram\n"
|
103 |
-
md2 += basic_stats["anony_vote_hist_md"] + "\n"
|
104 |
-
|
105 |
-
md3 = "### Model Call Histogram\n"
|
106 |
-
md3 += basic_stats["model_hist_md"] + "\n"
|
107 |
-
|
108 |
-
md4 = "### Model Call (Last 24 Hours)\n"
|
109 |
-
md4 += basic_stats["num_chats_last_24_hours"] + "\n"
|
110 |
-
|
111 |
-
basic_component_values[0] = md0
|
112 |
-
basic_component_values[1] = basic_stats["chat_dates_bar"]
|
113 |
-
basic_component_values[2] = md1
|
114 |
-
basic_component_values[3] = md2
|
115 |
-
basic_component_values[4] = md3
|
116 |
-
basic_component_values[5] = md4
|
117 |
-
|
118 |
-
|
119 |
-
def update_worker(max_num_files, interval, elo_results_file):
|
120 |
-
while True:
|
121 |
-
tic = time.time()
|
122 |
-
update_elo_components(max_num_files, elo_results_file)
|
123 |
-
durtaion = time.time() - tic
|
124 |
-
print(f"update duration: {durtaion:.2f} s")
|
125 |
-
time.sleep(max(interval - durtaion, 0))
|
126 |
-
|
127 |
|
128 |
def load_demo(url_params, request: gr.Request):
|
129 |
logger.info(f"load_demo. ip: {request.client.host}. params: {url_params}")
|
130 |
return basic_component_values + leader_component_values
|
131 |
|
|
|
|
|
132 |
|
133 |
-
|
134 |
-
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
|
135 |
-
|
136 |
-
|
137 |
-
def load_leaderboard_table_csv(filename, add_hyperlink=True):
|
138 |
-
lines = open(filename).readlines()
|
139 |
-
heads = [v.strip() for v in lines[0].split(",")]
|
140 |
-
rows = []
|
141 |
-
for i in range(1, len(lines)):
|
142 |
-
row = [v.strip() for v in lines[i].split(",")]
|
143 |
-
for j in range(len(heads)):
|
144 |
-
item = {}
|
145 |
-
for h, v in zip(heads, row):
|
146 |
-
if h == "Arena Elo rating":
|
147 |
-
if v != "-":
|
148 |
-
v = int(ast.literal_eval(v))
|
149 |
-
else:
|
150 |
-
v = np.nan
|
151 |
-
elif h == "MMLU":
|
152 |
-
if v != "-":
|
153 |
-
v = round(ast.literal_eval(v) * 100, 1)
|
154 |
-
else:
|
155 |
-
v = np.nan
|
156 |
-
elif h == "MT-bench (win rate %)":
|
157 |
-
if v != "-":
|
158 |
-
v = round(ast.literal_eval(v[:-1]), 1)
|
159 |
-
else:
|
160 |
-
v = np.nan
|
161 |
-
elif h == "MT-bench (score)":
|
162 |
-
if v != "-":
|
163 |
-
v = round(ast.literal_eval(v), 2)
|
164 |
-
else:
|
165 |
-
v = np.nan
|
166 |
-
item[h] = v
|
167 |
-
if add_hyperlink:
|
168 |
-
item["Model"] = model_hyperlink(item["Model"], item["Link"])
|
169 |
-
rows.append(item)
|
170 |
-
|
171 |
-
return rows
|
172 |
-
|
173 |
-
|
174 |
-
def build_basic_stats_tab():
|
175 |
-
empty = "Loading ..."
|
176 |
-
basic_component_values[:] = [empty, None, empty, empty, empty, empty]
|
177 |
-
|
178 |
-
md0 = gr.Markdown(empty)
|
179 |
-
gr.Markdown("#### Figure 1: Number of model calls and votes")
|
180 |
-
plot_1 = gr.Plot(show_label=False)
|
181 |
-
with gr.Row():
|
182 |
-
with gr.Column():
|
183 |
-
md1 = gr.Markdown(empty)
|
184 |
-
with gr.Column():
|
185 |
-
md2 = gr.Markdown(empty)
|
186 |
-
with gr.Row():
|
187 |
-
with gr.Column():
|
188 |
-
md3 = gr.Markdown(empty)
|
189 |
-
with gr.Column():
|
190 |
-
md4 = gr.Markdown(empty)
|
191 |
-
return [md0, plot_1, md1, md2, md3, md4]
|
192 |
-
|
193 |
-
def get_full_table(arena_df, model_table_df):
|
194 |
-
values = []
|
195 |
-
for i in range(len(model_table_df)):
|
196 |
-
row = []
|
197 |
-
model_key = model_table_df.iloc[i]["key"]
|
198 |
-
model_name = model_table_df.iloc[i]["Model"]
|
199 |
-
# model display name
|
200 |
-
row.append(model_name)
|
201 |
-
if model_key in arena_df.index:
|
202 |
-
idx = arena_df.index.get_loc(model_key)
|
203 |
-
row.append(round(arena_df.iloc[idx]["rating"]))
|
204 |
-
else:
|
205 |
-
row.append(np.nan)
|
206 |
-
row.append(model_table_df.iloc[i]["MT-bench (score)"])
|
207 |
-
row.append(model_table_df.iloc[i]["MMLU"])
|
208 |
-
# Organization
|
209 |
-
row.append(model_table_df.iloc[i]["Organization"])
|
210 |
-
# license
|
211 |
-
row.append(model_table_df.iloc[i]["License"])
|
212 |
-
|
213 |
-
values.append(row)
|
214 |
-
values.sort(key=lambda x: -x[1] if not np.isnan(x[1]) else 1e9)
|
215 |
-
return values
|
216 |
-
|
217 |
-
def create_ranking_str(ranking, ranking_difference):
|
218 |
-
if ranking_difference > 0:
|
219 |
-
# return f"{int(ranking)} (\u2191{int(ranking_difference)})"
|
220 |
-
return f"{int(ranking)} \u2191"
|
221 |
-
elif ranking_difference < 0:
|
222 |
-
# return f"{int(ranking)} (\u2193{int(-ranking_difference)})"
|
223 |
-
return f"{int(ranking)} \u2193"
|
224 |
-
else:
|
225 |
-
return f"{int(ranking)}"
|
226 |
-
|
227 |
-
def recompute_final_ranking(arena_df):
|
228 |
-
# compute ranking based on CI
|
229 |
-
ranking = {}
|
230 |
-
for i, model_a in enumerate(arena_df.index):
|
231 |
-
ranking[model_a] = 1
|
232 |
-
for j, model_b in enumerate(arena_df.index):
|
233 |
-
if i == j:
|
234 |
-
continue
|
235 |
-
if arena_df.loc[model_b]["rating_q025"] > arena_df.loc[model_a]["rating_q975"]:
|
236 |
-
ranking[model_a] += 1
|
237 |
-
return list(ranking.values())
|
238 |
-
|
239 |
-
def get_arena_table(arena_df, model_table_df, arena_subset_df=None):
|
240 |
-
arena_df = arena_df.sort_values(by=["final_ranking", "rating"], ascending=[True, False])
|
241 |
-
arena_df = arena_df[arena_df["num_battles"] > 2000]
|
242 |
-
arena_df["final_ranking"] = recompute_final_ranking(arena_df)
|
243 |
-
arena_df = arena_df.sort_values(by=["final_ranking"], ascending=True)
|
244 |
-
|
245 |
-
# arena_df["final_ranking"] = range(1, len(arena_df) + 1)
|
246 |
-
# sort by rating
|
247 |
-
if arena_subset_df is not None:
|
248 |
-
# filter out models not in the arena_df
|
249 |
-
arena_subset_df = arena_subset_df[arena_subset_df.index.isin(arena_df.index)]
|
250 |
-
arena_subset_df = arena_subset_df.sort_values(by=["rating"], ascending=False)
|
251 |
-
# arena_subset_df = arena_subset_df.sort_values(by=["final_ranking"], ascending=True)
|
252 |
-
# arena_subset_df = arena_subset_df[arena_subset_df["num_battles"] > 500]
|
253 |
-
arena_subset_df["final_ranking"] = recompute_final_ranking(arena_subset_df)
|
254 |
-
# keep only the models in the subset in arena_df and recompute final_ranking
|
255 |
-
arena_df = arena_df[arena_df.index.isin(arena_subset_df.index)]
|
256 |
-
# recompute final ranking
|
257 |
-
arena_df["final_ranking"] = recompute_final_ranking(arena_df)
|
258 |
-
|
259 |
-
# assign ranking by the order
|
260 |
-
arena_subset_df["final_ranking_no_tie"] = range(1, len(arena_subset_df) + 1)
|
261 |
-
arena_df["final_ranking_no_tie"] = range(1, len(arena_df) + 1)
|
262 |
-
# join arena_df and arena_subset_df on index
|
263 |
-
arena_df = arena_subset_df.join(arena_df["final_ranking"], rsuffix="_global", how="inner")
|
264 |
-
arena_df["ranking_difference"] = arena_df["final_ranking_global"] - arena_df["final_ranking"]
|
265 |
-
|
266 |
-
# no tie version
|
267 |
-
# arena_df = arena_subset_df.join(arena_df["final_ranking_no_tie"], rsuffix="_global", how="inner")
|
268 |
-
# arena_df["ranking_difference"] = arena_df["final_ranking_no_tie_global"] - arena_df["final_ranking_no_tie"]
|
269 |
-
|
270 |
-
arena_df = arena_df.sort_values(by=["final_ranking", "rating"], ascending=[True, False])
|
271 |
-
arena_df["final_ranking"] = arena_df.apply(lambda x: create_ranking_str(x["final_ranking"], x["ranking_difference"]), axis=1)
|
272 |
-
|
273 |
-
values = []
|
274 |
-
for i in range(len(arena_df)):
|
275 |
-
row = []
|
276 |
-
model_key = arena_df.index[i]
|
277 |
-
try: # this is a janky fix for where the model key is not in the model table (model table and arena table dont contain all the same models)
|
278 |
-
model_name = model_table_df[model_table_df["key"] == model_key]["Model"].values[
|
279 |
-
0
|
280 |
-
]
|
281 |
-
# rank
|
282 |
-
ranking = arena_df.iloc[i].get("final_ranking") or i+1
|
283 |
-
row.append(ranking)
|
284 |
-
if arena_subset_df is not None:
|
285 |
-
row.append(arena_df.iloc[i].get("ranking_difference") or 0)
|
286 |
-
# model display name
|
287 |
-
row.append(model_name)
|
288 |
-
# elo rating
|
289 |
-
row.append(round(arena_df.iloc[i]["rating"]))
|
290 |
-
upper_diff = round(
|
291 |
-
arena_df.iloc[i]["rating_q975"] - arena_df.iloc[i]["rating"]
|
292 |
-
)
|
293 |
-
lower_diff = round(
|
294 |
-
arena_df.iloc[i]["rating"] - arena_df.iloc[i]["rating_q025"]
|
295 |
-
)
|
296 |
-
row.append(f"+{upper_diff}/-{lower_diff}")
|
297 |
-
# num battles
|
298 |
-
row.append(round(arena_df.iloc[i]["num_battles"]))
|
299 |
-
# Organization
|
300 |
-
row.append(
|
301 |
-
model_table_df[model_table_df["key"] == model_key]["Organization"].values[0]
|
302 |
-
)
|
303 |
-
# license
|
304 |
-
row.append(
|
305 |
-
model_table_df[model_table_df["key"] == model_key]["License"].values[0]
|
306 |
-
)
|
307 |
-
cutoff_date = model_table_df[model_table_df["key"] == model_key]["Knowledge cutoff date"].values[0]
|
308 |
-
if cutoff_date == "-":
|
309 |
-
row.append("Unknown")
|
310 |
-
else:
|
311 |
-
row.append(cutoff_date)
|
312 |
-
values.append(row)
|
313 |
-
except Exception as e:
|
314 |
-
print(f"{model_key} - {e}")
|
315 |
-
return values
|
316 |
-
|
317 |
-
key_to_category_name = {
|
318 |
-
"full": "Overall",
|
319 |
-
"coding": "Coding",
|
320 |
-
"long_user": "Longer Query",
|
321 |
-
"english": "English",
|
322 |
-
"chinese": "Chinese",
|
323 |
-
"french": "French",
|
324 |
-
"no_tie": "Exclude Ties",
|
325 |
-
"no_short": "Exclude Short",
|
326 |
-
"no_refusal": "Exclude Refusal",
|
327 |
-
}
|
328 |
-
cat_name_to_explanation = {
|
329 |
-
"Overall": "Overall Questions",
|
330 |
-
"Coding": "Coding: whether conversation contains code snippets",
|
331 |
-
"Longer Query": "Longer Query (>= 500 tokens)",
|
332 |
-
"English": "English Prompts",
|
333 |
-
"Chinese": "Chinese Prompts",
|
334 |
-
"French": "French Prompts",
|
335 |
-
"Exclude Ties": "Exclude Ties and Bothbad",
|
336 |
-
"Exclude Short": "User Query >= 5 tokens",
|
337 |
-
"Exclude Refusal": 'Exclude model responses with refusal (e.g., "I cannot answer")',
|
338 |
-
}
|
339 |
-
|
340 |
-
|
341 |
-
def build_leaderboard_tab(elo_results_file, leaderboard_table_file, show_plot=False):
|
342 |
-
arena_dfs = {}
|
343 |
-
category_elo_results = {}
|
344 |
-
if elo_results_file is None: # Do live update
|
345 |
-
default_md = "Loading ..."
|
346 |
-
p1 = p2 = p3 = p4 = None
|
347 |
-
else:
|
348 |
-
with open(elo_results_file, "rb") as fin:
|
349 |
-
elo_results = pickle.load(fin)
|
350 |
-
if "full" in elo_results:
|
351 |
-
print("KEYS ", elo_results.keys())
|
352 |
-
for k in key_to_category_name.keys():
|
353 |
-
if k not in elo_results:
|
354 |
-
continue
|
355 |
-
arena_dfs[key_to_category_name[k]] = elo_results[k]["leaderboard_table_df"]
|
356 |
-
category_elo_results[key_to_category_name[k]] = elo_results[k]
|
357 |
-
|
358 |
-
p1 = category_elo_results["Overall"]["win_fraction_heatmap"]
|
359 |
-
p2 = category_elo_results["Overall"]["battle_count_heatmap"]
|
360 |
-
p3 = category_elo_results["Overall"]["bootstrap_elo_rating"]
|
361 |
-
p4 = category_elo_results["Overall"]["average_win_rate_bar"]
|
362 |
-
arena_df = arena_dfs["Overall"]
|
363 |
-
default_md = make_default_md(arena_df, category_elo_results["Overall"])
|
364 |
-
|
365 |
-
md_1 = gr.Markdown(default_md, elem_id="leaderboard_markdown")
|
366 |
-
if leaderboard_table_file:
|
367 |
-
data = load_leaderboard_table_csv(leaderboard_table_file)
|
368 |
-
model_table_df = pd.DataFrame(data)
|
369 |
|
|
|
|
|
|
|
|
|
|
|
370 |
with gr.Tabs() as tabs:
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
with gr.Row():
|
377 |
-
with gr.Column(scale=2):
|
378 |
-
category_dropdown = gr.Dropdown(choices=list(arena_dfs.keys()), label="Category", value="Overall")
|
379 |
-
default_category_details = make_category_arena_leaderboard_md(arena_df, arena_df, name="Overall")
|
380 |
-
with gr.Column(scale=4, variant="panel"):
|
381 |
-
category_deets = gr.Markdown(default_category_details, elem_id="category_deets")
|
382 |
-
|
383 |
-
elo_display_df = gr.Dataframe(
|
384 |
-
headers=[
|
385 |
-
"Rank",
|
386 |
-
"π€ Model",
|
387 |
-
"β Arena Elo",
|
388 |
-
"π 95% CI",
|
389 |
-
"π³οΈ Votes",
|
390 |
-
"Organization",
|
391 |
-
"License",
|
392 |
-
"Knowledge Cutoff",
|
393 |
-
],
|
394 |
-
datatype=[
|
395 |
-
"number",
|
396 |
-
"markdown",
|
397 |
-
"number",
|
398 |
-
"str",
|
399 |
-
"number",
|
400 |
-
"str",
|
401 |
-
"str",
|
402 |
-
"str",
|
403 |
-
],
|
404 |
-
value=arena_table_vals,
|
405 |
-
elem_id="arena_leaderboard_dataframe",
|
406 |
-
height=700,
|
407 |
-
column_widths=[70, 190, 110, 100, 90, 160, 150, 140],
|
408 |
-
wrap=True,
|
409 |
)
|
410 |
|
411 |
-
|
412 |
-
|
413 |
-
A model is ranked higher only if its lower bound of model score is higher than the upper bound of the other model's score.
|
414 |
-
See Figure 3 below for visualization of the confidence intervals. More details in [notebook]({notebook_url}).
|
415 |
-
""",
|
416 |
-
elem_id="leaderboard_markdown"
|
417 |
-
)
|
418 |
-
|
419 |
-
leader_component_values[:] = [default_md, p1, p2, p3, p4]
|
420 |
-
|
421 |
-
if show_plot:
|
422 |
-
more_stats_md = gr.Markdown(
|
423 |
-
f"""## More Statistics for Chatbot Arena (Overall)""",
|
424 |
-
elem_id="leaderboard_header_markdown"
|
425 |
-
)
|
426 |
-
with gr.Row():
|
427 |
-
with gr.Column():
|
428 |
-
gr.Markdown(
|
429 |
-
"#### Figure 1: Fraction of Model A Wins for All Non-tied A vs. B Battles", elem_id="plot-title"
|
430 |
-
)
|
431 |
-
plot_1 = gr.Plot(p1, show_label=False, elem_id="plot-container")
|
432 |
-
with gr.Column():
|
433 |
-
gr.Markdown(
|
434 |
-
"#### Figure 2: Battle Count for Each Combination of Models (without Ties)", elem_id="plot-title"
|
435 |
-
)
|
436 |
-
plot_2 = gr.Plot(p2, show_label=False)
|
437 |
-
with gr.Row():
|
438 |
-
with gr.Column():
|
439 |
-
gr.Markdown(
|
440 |
-
"#### Figure 3: Confidence Intervals on Model Strength (via Bootstrapping)", elem_id="plot-title"
|
441 |
-
)
|
442 |
-
plot_3 = gr.Plot(p3, show_label=False)
|
443 |
-
with gr.Column():
|
444 |
-
gr.Markdown(
|
445 |
-
"#### Figure 4: Average Win Rate Against All Other Models (Assuming Uniform Sampling and No Ties)", elem_id="plot-title"
|
446 |
-
)
|
447 |
-
plot_4 = gr.Plot(p4, show_label=False)
|
448 |
-
|
449 |
-
with gr.Tab("Full Leaderboard", id=1):
|
450 |
-
md = make_full_leaderboard_md(elo_results)
|
451 |
-
gr.Markdown(md, elem_id="leaderboard_markdown")
|
452 |
-
full_table_vals = get_full_table(arena_df, model_table_df)
|
453 |
-
gr.Dataframe(
|
454 |
-
headers=[
|
455 |
-
"π€ Model",
|
456 |
-
"β Arena Elo",
|
457 |
-
"π MT-bench",
|
458 |
-
"π MMLU",
|
459 |
-
"Organization",
|
460 |
-
"License",
|
461 |
-
],
|
462 |
-
datatype=["markdown", "number", "number", "number", "str", "str"],
|
463 |
-
value=full_table_vals,
|
464 |
-
elem_id="full_leaderboard_dataframe",
|
465 |
-
column_widths=[200, 100, 100, 100, 150, 150],
|
466 |
-
height=700,
|
467 |
-
wrap=True,
|
468 |
-
)
|
469 |
-
if not show_plot:
|
470 |
-
gr.Markdown(
|
471 |
-
""" ## Visit our [HF space](https://huggingface.co/spaces/lmsys/chatbot-arena-leaderboard) for more analysis!
|
472 |
-
If you want to see more models, please help us [add them](https://github.com/lm-sys/FastChat/blob/main/docs/arena.md#how-to-add-a-new-model).
|
473 |
-
""",
|
474 |
-
elem_id="leaderboard_markdown",
|
475 |
-
)
|
476 |
-
else:
|
477 |
-
pass
|
478 |
-
|
479 |
-
def update_leaderboard_df(arena_table_vals):
|
480 |
-
elo_datarame = pd.DataFrame(arena_table_vals, columns=[ "Rank", "Delta", "π€ Model", "β Arena Elo", "π 95% CI", "π³οΈ Votes", "Organization", "License", "Knowledge Cutoff"])
|
481 |
-
|
482 |
-
# goal: color the rows based on the rank with styler
|
483 |
-
def highlight_max(s):
|
484 |
-
# all items in S which contain up arrow should be green, down arrow should be red, otherwise black
|
485 |
-
return ["color: green; font-weight: bold" if "\u2191" in v else "color: red; font-weight: bold" if "\u2193" in v else "" for v in s]
|
486 |
-
|
487 |
-
def highlight_rank_max(s):
|
488 |
-
return ["color: green; font-weight: bold" if v > 0 else "color: red; font-weight: bold" if v < 0 else "" for v in s]
|
489 |
-
|
490 |
-
return elo_datarame.style.apply(highlight_max, subset=["Rank"]).apply(highlight_rank_max, subset=["Delta"])
|
491 |
-
|
492 |
-
def update_leaderboard_and_plots(category):
|
493 |
-
arena_subset_df = arena_dfs[category]
|
494 |
-
arena_subset_df = arena_subset_df[arena_subset_df["num_battles"] > 500]
|
495 |
-
elo_subset_results = category_elo_results[category]
|
496 |
-
arena_df = arena_dfs["Overall"]
|
497 |
-
arena_values = get_arena_table(arena_df, model_table_df, arena_subset_df = arena_subset_df if category != "Overall" else None)
|
498 |
-
if category != "Overall":
|
499 |
-
arena_values = update_leaderboard_df(arena_values)
|
500 |
-
arena_values = gr.Dataframe(
|
501 |
-
headers=[
|
502 |
-
"Rank",
|
503 |
-
"Delta",
|
504 |
-
"π€ Model",
|
505 |
-
"β Arena Elo",
|
506 |
-
"π 95% CI",
|
507 |
-
"π³οΈ Votes",
|
508 |
-
"Organization",
|
509 |
-
"License",
|
510 |
-
"Knowledge Cutoff",
|
511 |
-
],
|
512 |
-
datatype=[
|
513 |
-
"number",
|
514 |
-
"number",
|
515 |
-
"markdown",
|
516 |
-
"number",
|
517 |
-
"str",
|
518 |
-
"number",
|
519 |
-
"str",
|
520 |
-
"str",
|
521 |
-
"str",
|
522 |
-
],
|
523 |
-
value=arena_values,
|
524 |
-
elem_id="arena_leaderboard_dataframe",
|
525 |
-
height=700,
|
526 |
-
column_widths=[60, 70, 190, 110, 100, 90, 160, 150, 140],
|
527 |
-
wrap=True,
|
528 |
-
)
|
529 |
-
else:
|
530 |
-
arena_values = gr.Dataframe(
|
531 |
-
headers=[
|
532 |
-
"Rank",
|
533 |
-
"π€ Model",
|
534 |
-
"β Arena Elo",
|
535 |
-
"π 95% CI",
|
536 |
-
"π³οΈ Votes",
|
537 |
-
"Organization",
|
538 |
-
"License",
|
539 |
-
"Knowledge Cutoff",
|
540 |
-
],
|
541 |
-
datatype=[
|
542 |
-
"number",
|
543 |
-
"markdown",
|
544 |
-
"number",
|
545 |
-
"str",
|
546 |
-
"number",
|
547 |
-
"str",
|
548 |
-
"str",
|
549 |
-
"str",
|
550 |
-
],
|
551 |
-
value=arena_values,
|
552 |
-
elem_id="arena_leaderboard_dataframe",
|
553 |
-
height=700,
|
554 |
-
column_widths=[70, 190, 110, 100, 90, 160, 150, 140],
|
555 |
-
wrap=True,
|
556 |
-
)
|
557 |
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
leaderboard_md = make_category_arena_leaderboard_md(arena_df, arena_subset_df, name=category)
|
565 |
-
return arena_values, p1, p2, p3, p4, more_stats_md, leaderboard_md
|
566 |
-
|
567 |
-
category_dropdown.change(update_leaderboard_and_plots, inputs=[category_dropdown], outputs=[elo_display_df, plot_1, plot_2, plot_3, plot_4, more_stats_md, category_deets])
|
568 |
-
|
569 |
-
with gr.Accordion(
|
570 |
-
"π Citation",
|
571 |
-
open=True,
|
572 |
-
):
|
573 |
-
citation_md = """
|
574 |
-
### Citation
|
575 |
-
Please cite the following paper if you find our leaderboard or dataset helpful.
|
576 |
-
```
|
577 |
-
@misc{chiang2024chatbot,
|
578 |
-
title={Chatbot Arena: An Open Platform for Evaluating LLMs by Human Preference},
|
579 |
-
author={Wei-Lin Chiang and Lianmin Zheng and Ying Sheng and Anastasios Nikolas Angelopoulos and Tianle Li and Dacheng Li and Hao Zhang and Banghua Zhu and Michael Jordan and Joseph E. Gonzalez and Ion Stoica},
|
580 |
-
year={2024},
|
581 |
-
eprint={2403.04132},
|
582 |
-
archivePrefix={arXiv},
|
583 |
-
primaryClass={cs.AI}
|
584 |
-
}
|
585 |
-
"""
|
586 |
-
gr.Markdown(citation_md, elem_id="leaderboard_markdown")
|
587 |
-
gr.Markdown(acknowledgment_md)
|
588 |
-
|
589 |
-
if show_plot:
|
590 |
-
return [md_1, plot_1, plot_2, plot_3, plot_4]
|
591 |
-
return [md_1]
|
592 |
-
|
593 |
-
|
594 |
-
block_css = """
|
595 |
-
#notice_markdown {
|
596 |
-
font-size: 104%
|
597 |
-
}
|
598 |
-
#notice_markdown th {
|
599 |
-
display: none;
|
600 |
-
}
|
601 |
-
#notice_markdown td {
|
602 |
-
padding-top: 6px;
|
603 |
-
padding-bottom: 6px;
|
604 |
-
}
|
605 |
-
|
606 |
-
#category_deets {
|
607 |
-
text-align: center;
|
608 |
-
padding: 0px;
|
609 |
-
padding-left: 5px;
|
610 |
-
}
|
611 |
-
|
612 |
-
#leaderboard_markdown {
|
613 |
-
font-size: 104%
|
614 |
-
}
|
615 |
-
#leaderboard_markdown td {
|
616 |
-
padding-top: 6px;
|
617 |
-
padding-bottom: 6px;
|
618 |
-
}
|
619 |
-
|
620 |
-
#leaderboard_header_markdown {
|
621 |
-
font-size: 104%;
|
622 |
-
text-align: center;
|
623 |
-
display:block;
|
624 |
-
}
|
625 |
-
|
626 |
-
#leaderboard_dataframe td {
|
627 |
-
line-height: 0.1em;
|
628 |
-
}
|
629 |
-
|
630 |
-
#plot-title {
|
631 |
-
text-align: center;
|
632 |
-
display:block;
|
633 |
-
}
|
634 |
-
|
635 |
-
#non-interactive-button {
|
636 |
-
display: inline-block;
|
637 |
-
padding: 10px 10px;
|
638 |
-
background-color: #f7f7f7; /* Super light grey background */
|
639 |
-
text-align: center;
|
640 |
-
font-size: 26px; /* Larger text */
|
641 |
-
border-radius: 0; /* Straight edges, no border radius */
|
642 |
-
border: 0px solid #dcdcdc; /* A light grey border to match the background */
|
643 |
-
user-select: none; /* The text inside the button is not selectable */
|
644 |
-
pointer-events: none; /* The button is non-interactive */
|
645 |
-
}
|
646 |
-
|
647 |
-
footer {
|
648 |
-
display:none !important
|
649 |
-
}
|
650 |
-
.sponsor-image-about img {
|
651 |
-
margin: 0 20px;
|
652 |
-
margin-top: 20px;
|
653 |
-
height: 40px;
|
654 |
-
max-height: 100%;
|
655 |
-
width: auto;
|
656 |
-
float: left;
|
657 |
-
}
|
658 |
-
"""
|
659 |
-
|
660 |
-
acknowledgment_md = """
|
661 |
-
### Acknowledgment
|
662 |
-
We thank [Kaggle](https://www.kaggle.com/), [MBZUAI](https://mbzuai.ac.ae/), [a16z](https://www.a16z.com/), [Together AI](https://www.together.ai/), [Anyscale](https://www.anyscale.com/), [HuggingFace](https://huggingface.co/) for their generous [sponsorship](https://lmsys.org/donations/).
|
663 |
-
|
664 |
-
<div class="sponsor-image-about">
|
665 |
-
<img src="https://storage.googleapis.com/public-arena-asset/kaggle.png" alt="Kaggle">
|
666 |
-
<img src="https://storage.googleapis.com/public-arena-asset/mbzuai.jpeg" alt="MBZUAI">
|
667 |
-
<img src="https://storage.googleapis.com/public-arena-asset/a16z.jpeg" alt="a16z">
|
668 |
-
<img src="https://storage.googleapis.com/public-arena-asset/together.png" alt="Together AI">
|
669 |
-
<img src="https://storage.googleapis.com/public-arena-asset/anyscale.png" alt="AnyScale">
|
670 |
-
<img src="https://storage.googleapis.com/public-arena-asset/huggingface.png" alt="HuggingFace">
|
671 |
-
</div>
|
672 |
-
"""
|
673 |
-
|
674 |
-
def build_demo(elo_results_file, leaderboard_table_file):
|
675 |
-
text_size = gr.themes.sizes.text_lg
|
676 |
-
theme = gr.themes.Base(text_size=text_size)
|
677 |
-
theme.set(button_secondary_background_fill_hover="*primary_300",
|
678 |
-
button_secondary_background_fill_hover_dark="*primary_700")
|
679 |
-
with gr.Blocks(
|
680 |
-
title="Chatbot Arena Leaderboard",
|
681 |
-
theme=theme,
|
682 |
-
# theme = gr.themes.Base.load("theme.json"), # uncomment to use new cool theme
|
683 |
-
css=block_css,
|
684 |
-
) as demo:
|
685 |
-
leader_components = build_leaderboard_tab(
|
686 |
-
elo_results_file, leaderboard_table_file, show_plot=True
|
687 |
)
|
688 |
-
return demo
|
689 |
|
|
|
690 |
|
691 |
if __name__ == "__main__":
|
692 |
parser = argparse.ArgumentParser()
|
@@ -695,6 +48,9 @@ if __name__ == "__main__":
|
|
695 |
parser.add_argument("--port", type=int, default=7860)
|
696 |
args = parser.parse_args()
|
697 |
|
|
|
|
|
|
|
698 |
elo_result_files = glob.glob("elo_results_*.pkl")
|
699 |
def extract_sort_key(filename):
|
700 |
match = re.search(r'(\d{8})-(\d+)', filename)
|
@@ -706,14 +62,12 @@ if __name__ == "__main__":
|
|
706 |
else:
|
707 |
# Fallback sort key if the filename does not match the expected format
|
708 |
return (0, 0)
|
709 |
-
# elo_result_files.sort(key=lambda x: int(x[12:-4]))
|
710 |
elo_result_files.sort(key=lambda x: extract_sort_key(x[12:-4]))
|
711 |
elo_result_file = elo_result_files[-1]
|
712 |
|
713 |
leaderboard_table_files = glob.glob("leaderboard_table_*.csv")
|
714 |
leaderboard_table_files.sort(key=lambda x: extract_sort_key(x[18:-4]))
|
715 |
-
# leaderboard_table_files.sort(key=lambda x: int(x[18:-4]))
|
716 |
leaderboard_table_file = leaderboard_table_files[-1]
|
717 |
|
718 |
demo = build_demo(elo_result_file, leaderboard_table_file)
|
719 |
-
demo.launch(share=args.share, server_name=args.host, server_port=args.port)
|
|
|
1 |
+
from fastchat.serve.monitor.monitor import build_leaderboard_tab, build_basic_stats_tab, basic_component_values, leader_component_values
|
2 |
+
from fastchat.utils import build_logger, get_window_url_params_js
|
3 |
+
|
4 |
import argparse
|
5 |
import glob
|
|
|
|
|
|
|
|
|
|
|
6 |
import re
|
7 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def load_demo(url_params, request: gr.Request):
|
10 |
logger.info(f"load_demo. ip: {request.client.host}. params: {url_params}")
|
11 |
return basic_component_values + leader_component_values
|
12 |
|
13 |
+
def build_demo(elo_results_file, leaderboard_table_file):
|
14 |
+
from fastchat.serve.gradio_web_server import block_css
|
15 |
|
16 |
+
text_size = gr.themes.sizes.text_lg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
with gr.Blocks(
|
19 |
+
title="Monitor",
|
20 |
+
theme=gr.themes.Base(text_size=text_size),
|
21 |
+
css=block_css,
|
22 |
+
) as demo:
|
23 |
with gr.Tabs() as tabs:
|
24 |
+
with gr.Tab("Leaderboard", id=0):
|
25 |
+
leader_components = build_leaderboard_tab(
|
26 |
+
elo_results_file,
|
27 |
+
leaderboard_table_file,
|
28 |
+
show_plot=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
)
|
30 |
|
31 |
+
with gr.Tab("Basic Stats", id=1):
|
32 |
+
basic_components = build_basic_stats_tab()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
url_params = gr.JSON(visible=False)
|
35 |
+
demo.load(
|
36 |
+
load_demo,
|
37 |
+
[url_params],
|
38 |
+
basic_components + leader_components,
|
39 |
+
_js=get_window_url_params_js,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
)
|
|
|
41 |
|
42 |
+
return demo
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
parser = argparse.ArgumentParser()
|
|
|
48 |
parser.add_argument("--port", type=int, default=7860)
|
49 |
args = parser.parse_args()
|
50 |
|
51 |
+
logger = build_logger("monitor", "monitor.log")
|
52 |
+
logger.info(f"args: {args}")
|
53 |
+
|
54 |
elo_result_files = glob.glob("elo_results_*.pkl")
|
55 |
def extract_sort_key(filename):
|
56 |
match = re.search(r'(\d{8})-(\d+)', filename)
|
|
|
62 |
else:
|
63 |
# Fallback sort key if the filename does not match the expected format
|
64 |
return (0, 0)
|
|
|
65 |
elo_result_files.sort(key=lambda x: extract_sort_key(x[12:-4]))
|
66 |
elo_result_file = elo_result_files[-1]
|
67 |
|
68 |
leaderboard_table_files = glob.glob("leaderboard_table_*.csv")
|
69 |
leaderboard_table_files.sort(key=lambda x: extract_sort_key(x[18:-4]))
|
|
|
70 |
leaderboard_table_file = leaderboard_table_files[-1]
|
71 |
|
72 |
demo = build_demo(elo_result_file, leaderboard_table_file)
|
73 |
+
demo.launch(share=args.share, server_name=args.host, server_port=args.port)
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
plotly
|
|
|
|
1 |
+
plotly
|
2 |
+
git+https://github.com/lm-sys/FastChat.git@main
|