Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,53 @@
|
|
1 |
-
import
|
2 |
import pandas as pd
|
3 |
-
|
4 |
-
|
5 |
-
import re
|
6 |
-
from io import StringIO
|
7 |
-
from yall import create_yall
|
8 |
import plotly.graph_objs as go
|
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 |
def create_bar_chart(df, category):
|
49 |
"""Create a horizontal bar chart for the specified category."""
|
50 |
-
st.write(f"### {category} Scores")
|
51 |
sorted_df = df[['Model', category]].sort_values(by=category, ascending=True)
|
52 |
fig = go.Figure(go.Bar(
|
53 |
x=sorted_df[category],
|
@@ -62,164 +62,131 @@ def create_bar_chart(df, category):
|
|
62 |
margin=dict(l=20, r=20, t=20, b=20),
|
63 |
title=f"Leaderboard for {category} Scores"
|
64 |
)
|
65 |
-
|
66 |
-
|
67 |
-
def
|
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 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
st.dataframe(comparison_df)
|
173 |
-
|
174 |
-
if st.button("Export to CSV"):
|
175 |
-
csv_data = df.to_csv(index=False)
|
176 |
-
st.download_button(
|
177 |
-
label="Download CSV",
|
178 |
-
data=csv_data,
|
179 |
-
file_name="leaderboard.csv",
|
180 |
-
key="download-csv",
|
181 |
-
help="Click to download the CSV file",
|
182 |
-
)
|
183 |
-
if st.button("Fetch Merge-Configs"):
|
184 |
-
fetch_merge_configs(full_df)
|
185 |
-
st.success("Merge configurations have been fetched and saved.")
|
186 |
-
|
187 |
-
create_bar_chart(df, 'Filtered Average')
|
188 |
-
|
189 |
-
col1, col2 = st.columns(2)
|
190 |
-
with col1:
|
191 |
-
create_bar_chart(df, score_columns[1])
|
192 |
-
with col2:
|
193 |
-
create_bar_chart(df, score_columns[2])
|
194 |
-
|
195 |
-
col3, col4 = st.columns(2)
|
196 |
-
with col3:
|
197 |
-
create_bar_chart(df, score_columns[3])
|
198 |
-
with col4:
|
199 |
-
create_bar_chart(df, score_columns[4])
|
200 |
-
|
201 |
-
except Exception as e:
|
202 |
-
st.error("An error occurred while processing the markdown table.")
|
203 |
-
st.error(str(e))
|
204 |
-
else:
|
205 |
-
st.error("Failed to download the content from the URL provided.")
|
206 |
-
|
207 |
-
with tab2:
|
208 |
-
st.markdown('''
|
209 |
-
### Nous benchmark suite
|
210 |
-
Popularized by [Teknium](https://huggingface.co/teknium) and [NousResearch](https://huggingface.co/NousResearch), this benchmark suite aggregates four benchmarks:
|
211 |
-
* [**AGIEval**](https://arxiv.org/abs/2304.06364) (0-shot): `agieval_aqua_rat,agieval_logiqa_en,agieval_lsat_ar,agieval_lsat_lr,agieval_lsat_rc,agieval_sat_en,agieval_sat_en_without_passage,agieval_sat_math`
|
212 |
-
* **GPT4ALL** (0-shot): `hellaswag,openbookqa,winogrande,arc_easy,arc_challenge,boolq,piqa`
|
213 |
-
* [**TruthfulQA**](https://arxiv.org/abs/2109.07958) (0-shot): `truthfulqa_mc`
|
214 |
-
* [**Bigbench**](https://arxiv.org/abs/2206.04615) (0-shot): `bigbench_causal_judgement,bigbench_date_understanding,bigbench_disambiguation_qa,bigbench_geometric_shapes,bigbench_logical_deduction_five_objects,bigbench_logical_deduction_seven_objects,bigbench_logical_deduction_three_objects,bigbench_movie_recommendation,bigbench_navigate,bigbench_reasoning_about_colored_objects,bigbench_ruin_names,bigbench_salient_translation_error_detection,bigbench_snarks,bigbench_sports_understanding,bigbench_temporal_sequences,bigbench_tracking_shuffled_objects_five_objects,bigbench_tracking_shuffled_objects_seven_objects,bigbench_tracking_shuffled_objects_three_objects`
|
215 |
-
### Reproducibility
|
216 |
-
You can easily reproduce these results using 🧐 [LLM AutoEval](https://github.com/mlabonne/llm-autoeval/tree/master), a colab notebook that automates the evaluation process (benchmark: `nous`). This will upload the results to GitHub as gists. You can find the entire table with the links to the detailed results [here](https://gist.github.com/mlabonne/90294929a2dbcb8877f9696f28105fdf).
|
217 |
-
### Clone this space
|
218 |
-
You can create your own leaderboard with your LLM AutoEval results on GitHub Gist. You just need to clone this space and specify two variables:
|
219 |
-
* Change the `gist_id` in [yall.py](https://huggingface.co/spaces/mlabonne/Yet_Another_LLM_Leaderboard/blob/main/yall.py#L126).
|
220 |
-
* Create "New Secret" in Settings > Variables and secrets (name: "github", value: [your GitHub token](https://github.com/settings/tokens))
|
221 |
-
A special thanks to [gblazex](https://huggingface.co/gblazex) for providing many evaluations.
|
222 |
-
''')
|
223 |
|
224 |
if __name__ == "__main__":
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import seaborn as sns
|
|
|
|
|
|
|
5 |
import plotly.graph_objs as go
|
6 |
+
import plotly.offline as py
|
7 |
+
from io import StringIO
|
8 |
+
import base64
|
9 |
+
|
10 |
+
py.init_notebook_mode(connected=True)
|
11 |
+
|
12 |
+
# Read the data from the file
|
13 |
+
def parse_data(file_content):
|
14 |
+
lines = file_content.splitlines()
|
15 |
+
|
16 |
+
model_data = []
|
17 |
+
current_model = None
|
18 |
+
|
19 |
+
for line in lines:
|
20 |
+
line = line.strip()
|
21 |
+
if line.startswith('hf (pretrained='):
|
22 |
+
current_model = line.split('pretrained=')[1].split(',')[0]
|
23 |
+
elif line and current_model:
|
24 |
+
if not line.startswith('-') and '|' in line:
|
25 |
+
# Parse table row
|
26 |
+
parts = [p.strip() for p in line.split('|')]
|
27 |
+
if len(parts) >= 2: # Ensure the correct number of columns
|
28 |
+
try:
|
29 |
+
task_name = parts[0]
|
30 |
+
value = float(parts[1]) # Extract the numeric value
|
31 |
+
model_data.append([
|
32 |
+
current_model,
|
33 |
+
task_name, # Task name
|
34 |
+
value
|
35 |
+
])
|
36 |
+
except ValueError:
|
37 |
+
print(f"Skipping row due to invalid value: {parts}")
|
38 |
+
if not model_data:
|
39 |
+
print("No valid data found in the file.")
|
40 |
+
return pd.DataFrame(model_data, columns=['Model', 'Task', 'Value'])
|
41 |
+
|
42 |
+
# Calculate average performance
|
43 |
+
def calculate_averages(data):
|
44 |
+
if data.empty:
|
45 |
+
print("No data available to calculate averages.")
|
46 |
+
return pd.DataFrame(columns=['Model', 'Average Performance'])
|
47 |
+
return data.groupby('Model')['Value'].mean().reset_index().rename(columns={'Value': 'Average Performance'})
|
48 |
|
49 |
def create_bar_chart(df, category):
|
50 |
"""Create a horizontal bar chart for the specified category."""
|
|
|
51 |
sorted_df = df[['Model', category]].sort_values(by=category, ascending=True)
|
52 |
fig = go.Figure(go.Bar(
|
53 |
x=sorted_df[category],
|
|
|
62 |
margin=dict(l=20, r=20, t=20, b=20),
|
63 |
title=f"Leaderboard for {category} Scores"
|
64 |
)
|
65 |
+
return fig
|
66 |
+
|
67 |
+
def generate_visualizations(data, averages):
|
68 |
+
sns.set(style='whitegrid')
|
69 |
+
|
70 |
+
if averages.empty:
|
71 |
+
print("No averages to visualize.")
|
72 |
+
return None, None, None, None, None, None
|
73 |
+
|
74 |
+
averages = averages.sort_values(by='Average Performance')
|
75 |
+
|
76 |
+
# Matplotlib average performance plot
|
77 |
+
plt.figure(figsize=(12, 8))
|
78 |
+
sns.barplot(data=averages, x='Average Performance', y='Model', palette='viridis')
|
79 |
+
plt.title('Average Performance of Models', fontsize=16)
|
80 |
+
plt.xlabel('Average Performance', fontsize=12)
|
81 |
+
plt.ylabel('Model', fontsize=12)
|
82 |
+
plt.tight_layout()
|
83 |
+
|
84 |
+
# Save the plot to a buffer
|
85 |
+
buffer_avg = StringIO()
|
86 |
+
plt.savefig(buffer_avg, format='png')
|
87 |
+
buffer_avg.seek(0)
|
88 |
+
image_avg = base64.b64encode(buffer_avg.read()).decode('utf-8')
|
89 |
+
plt.close()
|
90 |
+
|
91 |
+
# Line plot for task performance by model
|
92 |
+
sorted_models = averages['Model'].tolist()
|
93 |
+
data['Model'] = pd.Categorical(data['Model'], categories=sorted_models, ordered=True)
|
94 |
+
data = data.sort_values(by=['Model', 'Task'])
|
95 |
+
|
96 |
+
if data.empty:
|
97 |
+
print("No data available for line plot.")
|
98 |
+
return image_avg, None, None, None, None, None
|
99 |
+
|
100 |
+
plt.figure(figsize=(14, 10))
|
101 |
+
sns.lineplot(data=data, x='Task', y='Value', hue='Model', marker='o')
|
102 |
+
plt.title('Task Performance by Model', fontsize=16)
|
103 |
+
plt.xlabel('Task', fontsize=12)
|
104 |
+
plt.ylabel('Performance', fontsize=12)
|
105 |
+
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', title='Model')
|
106 |
+
plt.xticks(rotation=45)
|
107 |
+
plt.tight_layout()
|
108 |
+
|
109 |
+
# Save the line plot to a buffer
|
110 |
+
buffer_line = StringIO()
|
111 |
+
plt.savefig(buffer_line, format='png')
|
112 |
+
buffer_line.seek(0)
|
113 |
+
image_line = base64.b64encode(buffer_line.read()).decode('utf-8')
|
114 |
+
plt.close()
|
115 |
+
|
116 |
+
# Heatmap of task performance
|
117 |
+
pivot_table = data.pivot_table(index='Task', columns='Model', values='Value')
|
118 |
+
plt.figure(figsize=(12, 10))
|
119 |
+
sns.heatmap(pivot_table, annot=True, fmt=".2f", cmap="coolwarm", cbar=True)
|
120 |
+
plt.title('Task Performance Heatmap', fontsize=16)
|
121 |
+
plt.xlabel('Model', fontsize=12)
|
122 |
+
plt.ylabel('Task', fontsize=12)
|
123 |
+
plt.tight_layout()
|
124 |
+
|
125 |
+
# Save the heatmap to a buffer
|
126 |
+
buffer_heatmap = StringIO()
|
127 |
+
plt.savefig(buffer_heatmap, format='png')
|
128 |
+
buffer_heatmap.seek(0)
|
129 |
+
image_heatmap = base64.b64encode(buffer_heatmap.read()).decode('utf-8')
|
130 |
+
plt.close()
|
131 |
+
|
132 |
+
# Boxplot of performance distribution per model
|
133 |
+
plt.figure(figsize=(12, 8))
|
134 |
+
sns.boxplot(data=data, x='Model', y='Value', palette='Set2')
|
135 |
+
plt.title('Performance Distribution per Model', fontsize=16)
|
136 |
+
plt.xlabel('Model', fontsize=12)
|
137 |
+
plt.ylabel('Performance', fontsize=12)
|
138 |
+
plt.xticks(rotation=45)
|
139 |
+
plt.tight_layout()
|
140 |
+
|
141 |
+
# Save the boxplot to a buffer
|
142 |
+
buffer_boxplot = StringIO()
|
143 |
+
plt.savefig(buffer_boxplot, format='png')
|
144 |
+
buffer_boxplot.seek(0)
|
145 |
+
image_boxplot = base64.b64encode(buffer_boxplot.read()).decode('utf-8')
|
146 |
+
plt.close()
|
147 |
+
|
148 |
+
# Create plotly bar charts
|
149 |
+
fig1 = create_bar_chart(averages, 'Average Performance')
|
150 |
+
plotly_avg = fig1.to_html(full_html=False)
|
151 |
+
|
152 |
+
plotly_tasks = {}
|
153 |
+
# Assuming you have tasks in the dataframe and want to display it
|
154 |
+
tasks = data['Task'].unique()
|
155 |
+
for task in tasks:
|
156 |
+
task_data = data[data['Task'] == task]
|
157 |
+
fig2 = create_bar_chart(task_data, 'Value')
|
158 |
+
fig2.update_layout(title=f"Leaderboard for {task} Scores")
|
159 |
+
plotly_tasks[task] = fig2.to_html(full_html=False)
|
160 |
+
|
161 |
+
return image_avg, image_line, image_heatmap, image_boxplot, plotly_avg, plotly_tasks
|
162 |
+
|
163 |
+
def process_and_visualize(file_content):
|
164 |
+
data = parse_data(file_content)
|
165 |
+
averages = calculate_averages(data)
|
166 |
+
|
167 |
+
image_avg, image_line, image_heatmap, image_boxplot, plotly_avg, plotly_tasks = generate_visualizations(data, averages)
|
168 |
+
|
169 |
+
output_text = f"Average Performance per Model:\n{averages.sort_values(by='Average Performance').to_string()}"
|
170 |
+
|
171 |
+
return output_text, image_avg, image_line, image_heatmap, image_boxplot, plotly_avg, plotly_tasks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
if __name__ == "__main__":
|
174 |
+
|
175 |
+
iface = gr.Interface(
|
176 |
+
fn=process_and_visualize,
|
177 |
+
inputs=gr.Textbox(lines=10, label="Paste your data here"),
|
178 |
+
outputs=[
|
179 |
+
gr.Textbox(label="Average Performance per Model"),
|
180 |
+
gr.Image(label="Matplotlib Average Performance Chart"),
|
181 |
+
gr.Image(label="Matplotlib Task Performance Line Chart"),
|
182 |
+
gr.Image(label="Matplotlib Task Performance Heatmap"),
|
183 |
+
gr.Image(label="Matplotlib Performance Distribution Boxplot"),
|
184 |
+
gr.HTML(label="Plotly Average Performance Chart"),
|
185 |
+
gr.Accordion(
|
186 |
+
[gr.HTML(label=f"Plotly {task} Chart") for task in ['tinyArc', 'tinyHellaswag', 'tinyMMLU', 'tinyTruthfulQA', 'tinyTruthfulQA_mc1', 'tinyWinogrande']], label="Task Charts"),
|
187 |
+
],
|
188 |
+
title="LLM Benchmark Visualizer",
|
189 |
+
description="Upload your LLM benchmark data and visualize the results."
|
190 |
+
)
|
191 |
+
|
192 |
+
iface.launch(share=True)
|