Spaces:
Running
Running
Quentin Mace
commited on
Commit
Β·
9749e52
1
Parent(s):
9331159
second first commit
Browse files- app.py +162 -43
- app/utils.py +25 -13
- data/dataset_handler.py +35 -0
- data/model_handler.py +60 -25
app.py
CHANGED
@@ -3,18 +3,36 @@ import gradio as gr
|
|
3 |
from app.utils import add_rank_and_format, filter_models, get_refresh_function
|
4 |
from data.model_handler import ModelHandler
|
5 |
|
6 |
-
METRICS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def main():
|
9 |
model_handler = ModelHandler()
|
10 |
initial_metric = "ndcg_at_5"
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
css = """
|
20 |
table > thead {
|
@@ -41,65 +59,167 @@ def main():
|
|
41 |
|
42 |
with gr.Blocks(css=css) as block:
|
43 |
with gr.Tabs():
|
44 |
-
with gr.TabItem("π Leaderboard"):
|
45 |
-
gr.Markdown("# ViDoRe:
|
46 |
-
gr.Markdown("###
|
47 |
|
48 |
gr.Markdown(
|
49 |
"""
|
50 |
-
Visual Document Retrieval Benchmark leaderboard. To submit results, refer to the corresponding tab.
|
51 |
|
52 |
-
Refer to the [ColPali paper](https://arxiv.org/abs/2407.01449) for details on metrics
|
53 |
"""
|
54 |
)
|
55 |
-
|
56 |
-
anchor_columns = list(data.columns[:3])
|
57 |
-
default_columns = anchor_columns + datasets_columns
|
58 |
|
59 |
with gr.Row():
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
with gr.Row():
|
65 |
-
|
66 |
-
|
67 |
|
68 |
-
def
|
69 |
-
|
70 |
-
data =
|
|
|
71 |
data = filter_models(data, search_term)
|
|
|
72 |
if selected_columns:
|
73 |
-
|
74 |
-
data = data[selected_columns]
|
75 |
return data
|
76 |
|
77 |
with gr.Row():
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
# Automatically refresh the dataframe when the dropdown value changes
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
)
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
)
|
|
|
94 |
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
gr.Markdown(
|
99 |
f"""
|
100 |
-
- **Total Datasets**: {
|
101 |
-
- **Total Scores**: {
|
102 |
-
- **Total Models**: {
|
103 |
"""
|
104 |
+ r"""
|
105 |
Please consider citing:
|
@@ -143,8 +263,8 @@ def main():
|
|
143 |
},
|
144 |
}
|
145 |
```
|
146 |
-
- The dataset names should be the same as the ViDoRe dataset names listed in the following
|
147 |
-
|
148 |
|
149 |
3. **Submit your model**:
|
150 |
- Create a public HuggingFace model repository with your model.
|
@@ -162,6 +282,5 @@ def main():
|
|
162 |
block.queue(max_size=10).launch(debug=True)
|
163 |
|
164 |
|
165 |
-
if __name__ == "__main__":
|
166 |
main()
|
167 |
-
|
|
|
3 |
from app.utils import add_rank_and_format, filter_models, get_refresh_function
|
4 |
from data.model_handler import ModelHandler
|
5 |
|
6 |
+
METRICS = [
|
7 |
+
"ndcg_at_1",
|
8 |
+
"ndcg_at_5",
|
9 |
+
"ndcg_at_10",
|
10 |
+
"ndcg_at_100",
|
11 |
+
"recall_at_1",
|
12 |
+
"recall_at_5",
|
13 |
+
"recall_at_10",
|
14 |
+
"recall_at_100",
|
15 |
+
]
|
16 |
+
|
17 |
|
18 |
def main():
|
19 |
model_handler = ModelHandler()
|
20 |
initial_metric = "ndcg_at_5"
|
21 |
|
22 |
+
model_handler.get_vidore_data(initial_metric)
|
23 |
+
data_benchmark_1 = model_handler.compute_averages(initial_metric, benchmark_version=1)
|
24 |
+
data_benchmark_1 = add_rank_and_format(data_benchmark_1, benchmark_version=1)
|
25 |
+
|
26 |
+
data_benchmark_2 = model_handler.compute_averages(initial_metric, benchmark_version=2)
|
27 |
+
data_benchmark_2 = add_rank_and_format(data_benchmark_2, benchmark_version=2)
|
28 |
|
29 |
+
NUM_DATASETS_1 = len(data_benchmark_1.columns) - 3
|
30 |
+
NUM_SCORES_1 = len(data_benchmark_1) * NUM_DATASETS_1
|
31 |
+
NUM_MODELS_1 = len(data_benchmark_1)
|
32 |
+
|
33 |
+
NUM_DATASETS_2 = len(data_benchmark_2.columns) - 3
|
34 |
+
NUM_SCORES_2 = len(data_benchmark_2) * NUM_DATASETS_2
|
35 |
+
NUM_MODELS_2 = len(data_benchmark_2)
|
36 |
|
37 |
css = """
|
38 |
table > thead {
|
|
|
59 |
|
60 |
with gr.Blocks(css=css) as block:
|
61 |
with gr.Tabs():
|
62 |
+
with gr.TabItem("π Leaderboard Benchmark 2"):
|
63 |
+
gr.Markdown("# ViDoRe 2: A new visual Document Retrieval Benchmark ππ")
|
64 |
+
gr.Markdown("### A harder dataset benchmark for visual document retrieval π")
|
65 |
|
66 |
gr.Markdown(
|
67 |
"""
|
68 |
+
Visual Document Retrieval Benchmark 2 leaderboard. To submit results, refer to the corresponding tab.
|
69 |
|
70 |
+
Refer to the [ColPali paper](https://arxiv.org/abs/2407.01449) for details on metrics and models.
|
71 |
"""
|
72 |
)
|
73 |
+
datasets_columns_2 = list(data_benchmark_2.columns[3:])
|
|
|
|
|
74 |
|
75 |
with gr.Row():
|
76 |
+
metric_dropdown_2 = gr.Dropdown(choices=METRICS, value=initial_metric, label="Select Metric")
|
77 |
+
research_textbox_2 = gr.Textbox(
|
78 |
+
placeholder="π Search Models... [press enter]",
|
79 |
+
label="Filter Models by Name",
|
80 |
+
)
|
81 |
+
column_checkboxes_2 = gr.CheckboxGroup(
|
82 |
+
choices=datasets_columns_2, value=datasets_columns_2, label="Select Columns to Display"
|
83 |
+
)
|
84 |
|
85 |
with gr.Row():
|
86 |
+
datatype_2 = ["number", "markdown"] + ["number"] * (NUM_DATASETS_2 + 1)
|
87 |
+
dataframe_2 = gr.Dataframe(data_benchmark_2, datatype=datatype_2, type="pandas")
|
88 |
|
89 |
+
def update_data_2(metric, search_term, selected_columns):
|
90 |
+
model_handler.get_vidore_data(metric)
|
91 |
+
data = model_handler.compute_averages(metric, benchmark_version=2)
|
92 |
+
data = add_rank_and_format(data, benchmark_version=2)
|
93 |
data = filter_models(data, search_term)
|
94 |
+
# data = remove_duplicates(data) # Add this line
|
95 |
if selected_columns:
|
96 |
+
data = data[["Rank", "Model", "Average"] + selected_columns]
|
|
|
97 |
return data
|
98 |
|
99 |
with gr.Row():
|
100 |
+
refresh_button_2 = gr.Button("Refresh")
|
101 |
+
refresh_button_2.click(
|
102 |
+
get_refresh_function(model_handler, benchmark_version=2),
|
103 |
+
inputs=[metric_dropdown_2],
|
104 |
+
outputs=dataframe_2,
|
105 |
+
concurrency_limit=20,
|
106 |
+
)
|
107 |
|
108 |
+
with gr.Row():
|
109 |
+
gr.Markdown(
|
110 |
+
"""
|
111 |
+
**Note**: For now, all models were evaluated using the vidore-benchmark package and custom retrievers on our side.
|
112 |
+
Those numbers are not numbers obtained from the organisations that released those models.
|
113 |
+
"""
|
114 |
+
)
|
115 |
|
116 |
# Automatically refresh the dataframe when the dropdown value changes
|
117 |
+
metric_dropdown_2.change(
|
118 |
+
get_refresh_function(model_handler, benchmark_version=2),
|
119 |
+
inputs=[metric_dropdown_2],
|
120 |
+
outputs=dataframe_2,
|
121 |
+
)
|
122 |
+
research_textbox_2.submit(
|
123 |
+
lambda metric, search_term, selected_columns: update_data_2(metric, search_term, selected_columns),
|
124 |
+
inputs=[metric_dropdown_2, research_textbox_2, column_checkboxes_2],
|
125 |
+
outputs=dataframe_2,
|
126 |
+
)
|
127 |
+
column_checkboxes_2.change(
|
128 |
+
lambda metric, search_term, selected_columns: update_data_2(metric, search_term, selected_columns),
|
129 |
+
inputs=[metric_dropdown_2, research_textbox_2, column_checkboxes_2],
|
130 |
+
outputs=dataframe_2,
|
131 |
+
)
|
132 |
+
|
133 |
+
gr.Markdown(
|
134 |
+
f"""
|
135 |
+
- **Total Datasets**: {NUM_DATASETS_2}
|
136 |
+
- **Total Scores**: {NUM_SCORES_2}
|
137 |
+
- **Total Models**: {NUM_MODELS_2}
|
138 |
+
"""
|
139 |
+
+ r"""
|
140 |
+
Please consider citing:
|
141 |
+
|
142 |
+
```bibtex
|
143 |
+
@misc{faysse2024colpaliefficientdocumentretrieval,
|
144 |
+
title={ColPali: Efficient Document Retrieval with Vision Language Models},
|
145 |
+
author={Manuel Faysse and Hugues Sibille and Tony Wu and Bilel Omrani and Gautier Viaud and CΓ©line Hudelot and Pierre Colombo},
|
146 |
+
year={2024},
|
147 |
+
eprint={2407.01449},
|
148 |
+
archivePrefix={arXiv},
|
149 |
+
primaryClass={cs.IR},
|
150 |
+
url={https://arxiv.org/abs/2407.01449},
|
151 |
+
}
|
152 |
+
```
|
153 |
+
"""
|
154 |
)
|
155 |
+
with gr.TabItem("π Leaderboard Benchmark 1"):
|
156 |
+
gr.Markdown("# ViDoRe: The Visual Document Retrieval Benchmark 1 ππ")
|
157 |
+
gr.Markdown("### From the paper - ColPali: Efficient Document Retrieval with Vision Language Models π")
|
158 |
+
|
159 |
+
gr.Markdown(
|
160 |
+
"""
|
161 |
+
Visual Document Retrieval Benchmark 1 leaderboard. To submit results, refer to the corresponding tab.
|
162 |
+
|
163 |
+
Refer to the [ColPali paper](https://arxiv.org/abs/2407.01449) for details on metrics, tasks and models.
|
164 |
+
"""
|
165 |
)
|
166 |
+
datasets_columns_1 = list(data_benchmark_1.columns[3:])
|
167 |
|
168 |
+
with gr.Row():
|
169 |
+
metric_dropdown_1 = gr.Dropdown(choices=METRICS, value=initial_metric, label="Select Metric")
|
170 |
+
research_textbox_1 = gr.Textbox(
|
171 |
+
placeholder="π Search Models... [press enter]",
|
172 |
+
label="Filter Models by Name",
|
173 |
+
)
|
174 |
+
column_checkboxes_1 = gr.CheckboxGroup(
|
175 |
+
choices=datasets_columns_1, value=datasets_columns_1, label="Select Columns to Display"
|
176 |
+
)
|
177 |
|
178 |
+
with gr.Row():
|
179 |
+
datatype_1 = ["number", "markdown"] + ["number"] * (NUM_DATASETS_1 + 1)
|
180 |
+
dataframe_1 = gr.Dataframe(data_benchmark_1, datatype=datatype_1, type="pandas")
|
181 |
+
|
182 |
+
def update_data_1(metric, search_term, selected_columns):
|
183 |
+
model_handler.get_vidore_data(metric)
|
184 |
+
data = model_handler.compute_averages(metric, benchmark_version=1)
|
185 |
+
data = add_rank_and_format(data, benchmark_version=1)
|
186 |
+
data = filter_models(data, search_term)
|
187 |
+
# data = remove_duplicates(data) # Add this line
|
188 |
+
if selected_columns:
|
189 |
+
data = data[["Rank", "Model", "Average"] + selected_columns]
|
190 |
+
return data
|
191 |
+
|
192 |
+
with gr.Row():
|
193 |
+
refresh_button_1 = gr.Button("Refresh")
|
194 |
+
refresh_button_1.click(
|
195 |
+
get_refresh_function(model_handler, benchmark_version=1),
|
196 |
+
inputs=[metric_dropdown_1],
|
197 |
+
outputs=dataframe_1,
|
198 |
+
concurrency_limit=20,
|
199 |
+
)
|
200 |
+
|
201 |
+
# Automatically refresh the dataframe when the dropdown value changes
|
202 |
+
metric_dropdown_1.change(
|
203 |
+
get_refresh_function(model_handler, benchmark_version=1),
|
204 |
+
inputs=[metric_dropdown_1],
|
205 |
+
outputs=dataframe_1,
|
206 |
+
)
|
207 |
+
research_textbox_1.submit(
|
208 |
+
lambda metric, search_term, selected_columns: update_data_1(metric, search_term, selected_columns),
|
209 |
+
inputs=[metric_dropdown_1, research_textbox_1, column_checkboxes_1],
|
210 |
+
outputs=dataframe_1,
|
211 |
+
)
|
212 |
+
column_checkboxes_1.change(
|
213 |
+
lambda metric, search_term, selected_columns: update_data_1(metric, search_term, selected_columns),
|
214 |
+
inputs=[metric_dropdown_1, research_textbox_1, column_checkboxes_1],
|
215 |
+
outputs=dataframe_1,
|
216 |
+
)
|
217 |
|
218 |
gr.Markdown(
|
219 |
f"""
|
220 |
+
- **Total Datasets**: {NUM_DATASETS_1}
|
221 |
+
- **Total Scores**: {NUM_SCORES_1}
|
222 |
+
- **Total Models**: {NUM_MODELS_1}
|
223 |
"""
|
224 |
+ r"""
|
225 |
Please consider citing:
|
|
|
263 |
},
|
264 |
}
|
265 |
```
|
266 |
+
- The dataset names should be the same as the ViDoRe and ViDoRe 2 dataset names listed in the following
|
267 |
+
collections: [ViDoRe Benchmark](https://huggingface.co/collections/vidore/vidore-benchmark-667173f98e70a1c0fa4db00d) and [ViDoRe Benchmark 2](vidore/vidore-benchmark-v2-dev-67ae03e3924e85b36e7f53b0).
|
268 |
|
269 |
3. **Submit your model**:
|
270 |
- Create a public HuggingFace model repository with your model.
|
|
|
282 |
block.queue(max_size=10).launch(debug=True)
|
283 |
|
284 |
|
285 |
+
if __name__ == "__main__":
|
286 |
main()
|
|
app/utils.py
CHANGED
@@ -1,31 +1,43 @@
|
|
1 |
from data.model_handler import ModelHandler
|
2 |
|
|
|
3 |
def make_clickable_model(model_name, link=None):
|
4 |
if link is None:
|
5 |
desanitized_model_name = model_name.replace("_", "/")
|
|
|
6 |
|
7 |
-
if
|
8 |
-
desanitized_model_name = desanitized_model_name.replace(
|
9 |
-
if
|
10 |
-
desanitized_model_name = desanitized_model_name.replace(
|
11 |
|
12 |
link = "https://huggingface.co/" + desanitized_model_name
|
13 |
|
14 |
-
return f'<a target="_blank" style="text-decoration: underline" href="{link}">{
|
15 |
|
16 |
|
17 |
-
def add_rank_and_format(df):
|
18 |
df = df.reset_index()
|
19 |
df = df.rename(columns={"index": "Model"})
|
20 |
-
df = ModelHandler.add_rank(df)
|
21 |
df["Model"] = df["Model"].apply(make_clickable_model)
|
|
|
22 |
return df
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def _refresh(metric):
|
26 |
-
model_handler
|
27 |
-
data_task_category = model_handler.
|
28 |
-
df = add_rank_and_format(data_task_category)
|
29 |
return df
|
30 |
|
31 |
return _refresh
|
@@ -33,5 +45,5 @@ def get_refresh_function():
|
|
33 |
|
34 |
def filter_models(data, search_term):
|
35 |
if search_term:
|
36 |
-
data = data[data[
|
37 |
-
return data
|
|
|
1 |
from data.model_handler import ModelHandler
|
2 |
|
3 |
+
|
4 |
def make_clickable_model(model_name, link=None):
|
5 |
if link is None:
|
6 |
desanitized_model_name = model_name.replace("_", "/")
|
7 |
+
desanitized_model_name = desanitized_model_name.replace("-thisisapoint-", ".")
|
8 |
|
9 |
+
if "/captioning" in desanitized_model_name:
|
10 |
+
desanitized_model_name = desanitized_model_name.replace("/captioning", "")
|
11 |
+
if "/ocr" in desanitized_model_name:
|
12 |
+
desanitized_model_name = desanitized_model_name.replace("/ocr", "")
|
13 |
|
14 |
link = "https://huggingface.co/" + desanitized_model_name
|
15 |
|
16 |
+
return f'<a target="_blank" style="text-decoration: underline" href="{link}">{desanitized_model_name}</a>'
|
17 |
|
18 |
|
19 |
+
def add_rank_and_format(df, benchmark_version=1):
|
20 |
df = df.reset_index()
|
21 |
df = df.rename(columns={"index": "Model"})
|
22 |
+
df = ModelHandler.add_rank(df, benchmark_version)
|
23 |
df["Model"] = df["Model"].apply(make_clickable_model)
|
24 |
+
# df = remove_duplicates(df)
|
25 |
return df
|
26 |
|
27 |
+
|
28 |
+
def remove_duplicates(df):
|
29 |
+
"""Remove duplicate models based on their name (after the last '/' if present)."""
|
30 |
+
df["model_name"] = df["Model"].str.replace("_", "/")
|
31 |
+
df = df.sort_values("Rank").drop_duplicates(subset=["model_name"], keep="first")
|
32 |
+
df = df.drop("model_name", axis=1)
|
33 |
+
return df
|
34 |
+
|
35 |
+
|
36 |
+
def get_refresh_function(model_handler, benchmark_version):
|
37 |
def _refresh(metric):
|
38 |
+
model_handler.get_vidore_data(metric)
|
39 |
+
data_task_category = model_handler.compute_averages(metric, benchmark_version)
|
40 |
+
df = add_rank_and_format(data_task_category, benchmark_version)
|
41 |
return df
|
42 |
|
43 |
return _refresh
|
|
|
45 |
|
46 |
def filter_models(data, search_term):
|
47 |
if search_term:
|
48 |
+
data = data[data["Model"].str.contains(search_term, case=False, na=False)]
|
49 |
+
return data
|
data/dataset_handler.py
CHANGED
@@ -11,6 +11,14 @@ VIDORE_DATASETS_KEYWORDS = [
|
|
11 |
"healthcare_industry",
|
12 |
]
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def get_datasets_nickname(dataset_name) -> str:
|
16 |
if "arxivqa" in dataset_name:
|
@@ -41,5 +49,32 @@ def get_datasets_nickname(dataset_name) -> str:
|
|
41 |
elif "healthcare_industry" in dataset_name:
|
42 |
return "Healthcare Industry"
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
else:
|
45 |
raise ValueError(f"Dataset {dataset_name} not found in ViDoRe")
|
|
|
11 |
"healthcare_industry",
|
12 |
]
|
13 |
|
14 |
+
VIDORE_2_DATASETS_KEYWORDS = [
|
15 |
+
"restaurant_esg",
|
16 |
+
"rse_restaurant",
|
17 |
+
"axa",
|
18 |
+
"mit_biomedical",
|
19 |
+
"economics_macro",
|
20 |
+
]
|
21 |
+
|
22 |
|
23 |
def get_datasets_nickname(dataset_name) -> str:
|
24 |
if "arxivqa" in dataset_name:
|
|
|
49 |
elif "healthcare_industry" in dataset_name:
|
50 |
return "Healthcare Industry"
|
51 |
|
52 |
+
elif "restaurant_esg" in dataset_name:
|
53 |
+
return "ESG Restaurant Human"
|
54 |
+
|
55 |
+
elif "rse_restaurant" in dataset_name and "multilingual" in dataset_name:
|
56 |
+
return "ESG Restaurant Synthetic Multilingual"
|
57 |
+
|
58 |
+
elif "rse_restaurant" in dataset_name:
|
59 |
+
return "ESG Restaurant Synthetic"
|
60 |
+
|
61 |
+
elif "axa" in dataset_name and "multilingual" in dataset_name:
|
62 |
+
return "AXA Multilingual"
|
63 |
+
|
64 |
+
elif "axa" in dataset_name:
|
65 |
+
return "AXA"
|
66 |
+
|
67 |
+
elif "mit_biomedical" in dataset_name and "multilingual" in dataset_name:
|
68 |
+
return "MIT Biomedical Multilingual"
|
69 |
+
|
70 |
+
elif "mit_biomedical" in dataset_name:
|
71 |
+
return "MIT Biomedical"
|
72 |
+
|
73 |
+
elif "economics_macro" in dataset_name and "multilingual" in dataset_name:
|
74 |
+
return "Economics Macro Multilingual"
|
75 |
+
|
76 |
+
elif "economics_macro" in dataset_name:
|
77 |
+
return "Economics Macro"
|
78 |
+
|
79 |
else:
|
80 |
raise ValueError(f"Dataset {dataset_name} not found in ViDoRe")
|
data/model_handler.py
CHANGED
@@ -5,7 +5,7 @@ from typing import Any, Dict
|
|
5 |
import pandas as pd
|
6 |
from huggingface_hub import HfApi, hf_hub_download, metadata_load
|
7 |
|
8 |
-
from .dataset_handler import VIDORE_DATASETS_KEYWORDS, get_datasets_nickname
|
9 |
|
10 |
BLOCKLIST = ["impactframes"]
|
11 |
|
@@ -29,15 +29,30 @@ class ModelHandler:
|
|
29 |
def _are_results_in_new_vidore_format(self, results: Dict[str, Any]) -> bool:
|
30 |
return "metadata" in results and "metrics" in results
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
def get_vidore_data(self, metric="ndcg_at_5"):
|
33 |
models = self.api.list_models(filter="vidore")
|
34 |
repositories = [model.modelId for model in models] # type: ignore
|
35 |
|
|
|
|
|
|
|
36 |
for repo_id in repositories:
|
37 |
org_name = repo_id.split("/")[0]
|
38 |
if org_name in BLOCKLIST:
|
39 |
continue
|
40 |
-
|
41 |
files = [f for f in self.api.list_repo_files(repo_id) if f.endswith("_metrics.json") or f == "results.json"]
|
42 |
|
43 |
if len(files) == 0:
|
@@ -45,39 +60,58 @@ class ModelHandler:
|
|
45 |
else:
|
46 |
for file in files:
|
47 |
if file.endswith("results.json"):
|
48 |
-
model_name = repo_id.replace("/", "_")
|
49 |
else:
|
50 |
model_name = file.split("_metrics.json")[0]
|
|
|
51 |
|
52 |
-
if
|
53 |
-
readme_path = hf_hub_download(repo_id, filename="README.md")
|
54 |
-
meta = metadata_load(readme_path)
|
55 |
-
try:
|
56 |
-
result_path = hf_hub_download(repo_id, filename=file)
|
57 |
|
58 |
-
|
59 |
-
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
results = results["metrics"]
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
continue
|
69 |
|
70 |
-
|
|
|
|
|
|
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
model_res = {}
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
76 |
dataset_res = {}
|
|
|
77 |
for dataset in res.keys():
|
78 |
-
|
79 |
-
if not any(keyword in dataset for keyword in VIDORE_DATASETS_KEYWORDS):
|
80 |
-
print(f"{dataset} not found in ViDoRe datasets. Skipping ...")
|
81 |
continue
|
82 |
|
83 |
dataset_nickname = get_datasets_nickname(dataset)
|
@@ -90,7 +124,7 @@ class ModelHandler:
|
|
90 |
return pd.DataFrame()
|
91 |
|
92 |
@staticmethod
|
93 |
-
def add_rank(df):
|
94 |
df.fillna(0.0, inplace=True)
|
95 |
cols_to_rank = [
|
96 |
col
|
@@ -104,6 +138,7 @@ class ModelHandler:
|
|
104 |
"Max Tokens",
|
105 |
]
|
106 |
]
|
|
|
107 |
if len(cols_to_rank) == 1:
|
108 |
df.sort_values(cols_to_rank[0], ascending=False, inplace=True)
|
109 |
else:
|
|
|
5 |
import pandas as pd
|
6 |
from huggingface_hub import HfApi, hf_hub_download, metadata_load
|
7 |
|
8 |
+
from .dataset_handler import VIDORE_2_DATASETS_KEYWORDS, VIDORE_DATASETS_KEYWORDS, get_datasets_nickname
|
9 |
|
10 |
BLOCKLIST = ["impactframes"]
|
11 |
|
|
|
29 |
def _are_results_in_new_vidore_format(self, results: Dict[str, Any]) -> bool:
|
30 |
return "metadata" in results and "metrics" in results
|
31 |
|
32 |
+
def _is_baseline_repo(self, repo_id: str) -> bool:
|
33 |
+
return repo_id == "vidore/baseline-results"
|
34 |
+
|
35 |
+
def sanitize_model_name(self, model_name):
|
36 |
+
return model_name.replace("/", "_").replace(".", "-thisisapoint-")
|
37 |
+
|
38 |
+
def fuze_model_infos(self, model_name, results):
|
39 |
+
for dataset, metrics in results.items():
|
40 |
+
if dataset not in self.model_infos[model_name]["results"].keys():
|
41 |
+
self.model_infos[model_name]["results"][dataset] = metrics
|
42 |
+
else:
|
43 |
+
continue
|
44 |
+
|
45 |
def get_vidore_data(self, metric="ndcg_at_5"):
|
46 |
models = self.api.list_models(filter="vidore")
|
47 |
repositories = [model.modelId for model in models] # type: ignore
|
48 |
|
49 |
+
# Sort repositories to process non-baseline repos first (to prioritize their results)
|
50 |
+
repositories.sort(key=lambda x: self._is_baseline_repo(x))
|
51 |
+
|
52 |
for repo_id in repositories:
|
53 |
org_name = repo_id.split("/")[0]
|
54 |
if org_name in BLOCKLIST:
|
55 |
continue
|
|
|
56 |
files = [f for f in self.api.list_repo_files(repo_id) if f.endswith("_metrics.json") or f == "results.json"]
|
57 |
|
58 |
if len(files) == 0:
|
|
|
60 |
else:
|
61 |
for file in files:
|
62 |
if file.endswith("results.json"):
|
63 |
+
model_name = repo_id.replace("/", "_").replace(".", "-thisisapoint-")
|
64 |
else:
|
65 |
model_name = file.split("_metrics.json")[0]
|
66 |
+
model_name = model_name.replace("/", "_").replace(".", "-thisisapoint-")
|
67 |
|
68 |
+
# Skip if the model is from baseline and we already have results
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
readme_path = hf_hub_download(repo_id, filename="README.md")
|
71 |
+
meta = metadata_load(readme_path)
|
72 |
+
try:
|
73 |
+
result_path = hf_hub_download(repo_id, filename=file)
|
74 |
|
75 |
+
with open(result_path) as f:
|
76 |
+
results = json.load(f)
|
|
|
77 |
|
78 |
+
if self._are_results_in_new_vidore_format(results):
|
79 |
+
metadata = results["metadata"]
|
80 |
+
results = results["metrics"]
|
|
|
81 |
|
82 |
+
# Handles the case where the model is both in baseline and outside of it
|
83 |
+
# (prioritizes the non-baseline results)
|
84 |
+
if self._is_baseline_repo(repo_id) and self.sanitize_model_name(model_name) in self.model_infos:
|
85 |
+
self.fuze_model_infos(model_name, results)
|
86 |
|
87 |
+
self.model_infos[model_name] = {"meta": meta, "results": results}
|
88 |
+
except Exception as e:
|
89 |
+
print(f"Error loading {model_name} - {e}")
|
90 |
+
continue
|
91 |
+
|
92 |
+
# In order to keep only models relevant to a benchmark
|
93 |
+
def filter_models_by_benchmark(self, benchmark_version=1):
|
94 |
+
filtered_model_infos = {}
|
95 |
+
keywords = VIDORE_DATASETS_KEYWORDS if benchmark_version == 1 else VIDORE_2_DATASETS_KEYWORDS
|
96 |
+
|
97 |
+
for model, info in self.model_infos.items():
|
98 |
+
results = info["results"]
|
99 |
+
if any(any(keyword in dataset for keyword in keywords) for dataset in results.keys()):
|
100 |
+
filtered_model_infos[model] = info
|
101 |
+
|
102 |
+
return filtered_model_infos
|
103 |
+
|
104 |
+
# Compute the average of a metric for each model,
|
105 |
+
def compute_averages(self, metric="ndcg_at_5", benchmark_version=1):
|
106 |
model_res = {}
|
107 |
+
filtered_model_infos = self.filter_models_by_benchmark(benchmark_version)
|
108 |
+
if len(filtered_model_infos) > 0:
|
109 |
+
for model in filtered_model_infos.keys():
|
110 |
+
res = filtered_model_infos[model]["results"]
|
111 |
dataset_res = {}
|
112 |
+
keywords = VIDORE_DATASETS_KEYWORDS if benchmark_version == 1 else VIDORE_2_DATASETS_KEYWORDS
|
113 |
for dataset in res.keys():
|
114 |
+
if not any(keyword in dataset for keyword in keywords):
|
|
|
|
|
115 |
continue
|
116 |
|
117 |
dataset_nickname = get_datasets_nickname(dataset)
|
|
|
124 |
return pd.DataFrame()
|
125 |
|
126 |
@staticmethod
|
127 |
+
def add_rank(df, benchmark_version=1):
|
128 |
df.fillna(0.0, inplace=True)
|
129 |
cols_to_rank = [
|
130 |
col
|
|
|
138 |
"Max Tokens",
|
139 |
]
|
140 |
]
|
141 |
+
|
142 |
if len(cols_to_rank) == 1:
|
143 |
df.sort_values(cols_to_rank[0], ascending=False, inplace=True)
|
144 |
else:
|