Spaces:
Runtime error
Runtime error
app: add initial version
Browse files
app.py
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
title = """
|
5 |
+
# hmLeaderboard
|
6 |
+
|
7 |
+
![hmLeaderboard](logo.png)
|
8 |
+
"""
|
9 |
+
|
10 |
+
description = """
|
11 |
+
## Space for tracking and ranking models on Historic NER Datasets.
|
12 |
+
|
13 |
+
At the moment the following models are supported:
|
14 |
+
|
15 |
+
* hmBERT: [Historical Multilingual Language Models for Named Entity Recognition](https://huggingface.co/hmbert).
|
16 |
+
* hmTEAMS: [Historic Multilingual TEAMS Models](https://huggingface.co/hmteams).
|
17 |
+
"""
|
18 |
+
footer = "Made from Bavarian Oberland with ❤️ and 🥨."
|
19 |
+
|
20 |
+
model_selection_file_names = {
|
21 |
+
"Best Configuration": "best_model_configurations.csv",
|
22 |
+
"Best Model": "best_models.csv"
|
23 |
+
}
|
24 |
+
|
25 |
+
df_init = pd.read_csv(model_selection_file_names["Best Configuration"])
|
26 |
+
dataset_names = df_init.columns.values[1:].tolist()
|
27 |
+
languages = list(set([dataset_name.split(" ")[0] for dataset_name in dataset_names]))
|
28 |
+
|
29 |
+
|
30 |
+
def perform_evaluation_for_datasets(model_selection, selected_datasets):
|
31 |
+
df = pd.read_csv(model_selection_file_names.get(model_selection))
|
32 |
+
|
33 |
+
selected_indices = []
|
34 |
+
|
35 |
+
for selected_dataset in selected_datasets:
|
36 |
+
selected_indices.append(dataset_names.index(selected_dataset) + 1)
|
37 |
+
|
38 |
+
mean_column = df.iloc[:, selected_indices].mean(axis=1).round(2)
|
39 |
+
|
40 |
+
# Include column with column name
|
41 |
+
result_df = df.iloc[:, [0] + selected_indices]
|
42 |
+
result_df["Average"] = mean_column
|
43 |
+
|
44 |
+
return result_df
|
45 |
+
|
46 |
+
def perform_evaluation_for_languages(model_selection, selected_languages):
|
47 |
+
df = pd.read_csv(model_selection_file_names.get(model_selection))
|
48 |
+
|
49 |
+
selected_indices = []
|
50 |
+
|
51 |
+
for selected_language in selected_languages:
|
52 |
+
selected_language = selected_language.lower()
|
53 |
+
found_indices = [i for i, column_name in enumerate(df.columns) if selected_language in column_name.lower()]
|
54 |
+
|
55 |
+
for found_index in found_indices:
|
56 |
+
selected_indices.append(found_index)
|
57 |
+
|
58 |
+
mean_column = df.iloc[:, selected_indices].mean(axis=1).round(2)
|
59 |
+
|
60 |
+
# Include column with column name
|
61 |
+
result_df = df.iloc[:, [0] + selected_indices]
|
62 |
+
result_df["Average"] = mean_column
|
63 |
+
|
64 |
+
return result_df
|
65 |
+
|
66 |
+
with gr.Blocks() as demo:
|
67 |
+
gr.Markdown(title)
|
68 |
+
gr.Markdown(description)
|
69 |
+
|
70 |
+
with gr.Tab("Overview"):
|
71 |
+
gr.Markdown("### Best Configuration\nThe best hyper-parameter configuration for each model is used and average F1-score over runs with different seeds is reported here:")
|
72 |
+
|
73 |
+
df_result = perform_evaluation_for_datasets("Best Configuration", dataset_names)
|
74 |
+
|
75 |
+
gr.Dataframe(value=df_result)
|
76 |
+
|
77 |
+
gr.Markdown("### Best Model\nThe best hyper-parameter configuration for each model is used and the model with highest F1-score is used and its performance is reported here:")
|
78 |
+
|
79 |
+
df_result = perform_evaluation_for_datasets("Best Model", dataset_names)
|
80 |
+
|
81 |
+
gr.Dataframe(value=df_result)
|
82 |
+
|
83 |
+
with gr.Tab("Filtering"):
|
84 |
+
|
85 |
+
gr.Markdown("### Filtering\nSwiss-knife filtering for single datasets and languages is possible.")
|
86 |
+
|
87 |
+
model_selection = gr.Radio(choices=["Best Configuration", "Best Model"],
|
88 |
+
label="Model Selection",
|
89 |
+
info="Defines if best configuration or best model should be used for evaluation. When 'Best Configuration' is used, the best hyper-parameter configuration is used and then averaged F1-score over all runs is calculated. When 'Best Model' is chosen, the best hyper-parameter configuration and model with highest F1-score on development dataset is used (best model).",
|
90 |
+
value="Best Configuration")
|
91 |
+
|
92 |
+
with gr.Tab("Dataset Selection"):
|
93 |
+
datasets_selection = gr.CheckboxGroup(
|
94 |
+
dataset_names, label="Datasets", info="Select datasets for evaluation"
|
95 |
+
)
|
96 |
+
output_df = gr.Dataframe()
|
97 |
+
|
98 |
+
evaluation_button = gr.Button("Evaluate")
|
99 |
+
evaluation_button.click(fn=perform_evaluation_for_datasets, inputs=[model_selection, datasets_selection], outputs=output_df)
|
100 |
+
|
101 |
+
|
102 |
+
with gr.Tab("Language Selection"):
|
103 |
+
language_selection = gr.CheckboxGroup(
|
104 |
+
languages, label="Languages", info="Select languages for evaluation"
|
105 |
+
)
|
106 |
+
output_df = gr.Dataframe()
|
107 |
+
|
108 |
+
evaluation_button = gr.Button("Evaluate")
|
109 |
+
evaluation_button.click(fn=perform_evaluation_for_languages, inputs=[model_selection, language_selection], outputs=output_df)
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
gr.Markdown(footer)
|
114 |
+
|
115 |
+
demo.launch()
|