HugSib commited on
Commit
1045c52
1 Parent(s): 4c1e130

feat : support for results.json

Browse files
Files changed (2) hide show
  1. data/dataset_handler.py +45 -64
  2. data/model_handler.py +20 -8
data/dataset_handler.py CHANGED
@@ -1,64 +1,45 @@
1
- from typing import Dict
2
- from huggingface_hub import get_collection
3
-
4
-
5
- def get_datasets_nickname() -> Dict:
6
- datasets_nickname = {}
7
-
8
- collection = get_collection("vidore/vidore-benchmark-667173f98e70a1c0fa4db00d")
9
- collection_items = collection.items
10
-
11
- for item in collection_items:
12
- dataset_name = item.item_id
13
-
14
- if 'arxivqa' in dataset_name:
15
- datasets_nickname[dataset_name] = 'ArxivQA'
16
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'ArxivQA'
17
- datasets_nickname[dataset_name + '_captioning'] = 'ArxivQA'
18
-
19
- elif 'docvqa' in dataset_name:
20
- datasets_nickname[dataset_name] = 'DocVQA'
21
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'DocVQA'
22
- datasets_nickname[dataset_name + '_captioning'] = 'DocVQA'
23
-
24
- elif 'infovqa' in dataset_name:
25
- datasets_nickname[dataset_name] = 'InfoVQA'
26
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'InfoVQA'
27
- datasets_nickname[dataset_name + '_captioning'] = 'InfoVQA'
28
-
29
- elif 'tabfquad' in dataset_name:
30
- datasets_nickname[dataset_name] = 'TabFQuad'
31
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'TabFQuad'
32
- datasets_nickname[dataset_name + '_captioning'] = 'TabFQuad'
33
-
34
- elif 'tatdqa' in dataset_name:
35
- datasets_nickname[dataset_name] = 'TATDQA'
36
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'TATDQA'
37
- datasets_nickname[dataset_name + '_captioning'] = 'TATDQA'
38
-
39
- elif 'shiftproject' in dataset_name:
40
- datasets_nickname[dataset_name] = 'ShiftProject'
41
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'ShiftProject'
42
- datasets_nickname[dataset_name + '_captioning'] = 'ShiftProject'
43
-
44
- elif 'artificial_intelligence' in dataset_name:
45
- datasets_nickname[dataset_name] = 'Artificial Intelligence'
46
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'Artificial Intelligence'
47
- datasets_nickname[dataset_name + '_captioning'] = 'Artificial Intelligence'
48
-
49
- elif 'energy' in dataset_name:
50
- datasets_nickname[dataset_name] = 'Energy'
51
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'Energy'
52
- datasets_nickname[dataset_name + '_captioning'] = 'Energy'
53
-
54
- elif 'government_reports' in dataset_name:
55
- datasets_nickname[dataset_name] = 'Government Reports'
56
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'Government Reports'
57
- datasets_nickname[dataset_name + '_captioning'] = 'Government Reports'
58
-
59
- elif 'healthcare' in dataset_name:
60
- datasets_nickname[dataset_name] = 'Healthcare'
61
- datasets_nickname[dataset_name + '_ocr_chunk'] = 'Healthcare'
62
- datasets_nickname[dataset_name + '_captioning'] = 'Healthcare'
63
-
64
- return datasets_nickname
 
1
+ VIDORE_DATASETS_KEYWORDS = [
2
+ "arxivqa",
3
+ "docvqa",
4
+ "infovqa",
5
+ "tabfquad",
6
+ "tatdqa",
7
+ "shift",
8
+ "artificial_intelligence",
9
+ "energy",
10
+ "government_reports",
11
+ "healthcare_industry",
12
+ ]
13
+
14
+
15
+ def get_datasets_nickname(dataset_name) -> str:
16
+ if "arxivqa" in dataset_name:
17
+ return "ArxivQA"
18
+
19
+ elif "docvqa" in dataset_name:
20
+ return "DocVQA"
21
+ elif "infovqa" in dataset_name:
22
+ return "InfoVQA"
23
+ elif "tabfquad" in dataset_name:
24
+ return "TabFQuad"
25
+
26
+ elif "tatdqa" in dataset_name:
27
+ return "TAT-DQA"
28
+
29
+ elif "shift" in dataset_name:
30
+ return "Shift Project"
31
+
32
+ elif "artificial_intelligence" in dataset_name:
33
+ return "Artificial Intelligence"
34
+
35
+ elif "energy" in dataset_name:
36
+ return "Energy"
37
+
38
+ elif "government_reports" in dataset_name:
39
+ return "Government Reports"
40
+
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")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
data/model_handler.py CHANGED
@@ -3,7 +3,7 @@ import os
3
  from typing import Dict
4
  from huggingface_hub import HfApi, hf_hub_download, metadata_load
5
  import pandas as pd
6
- from .dataset_handler import get_datasets_nickname
7
 
8
  class ModelHandler:
9
  def __init__(self, model_infos_path="model_infos.json"):
@@ -25,14 +25,18 @@ class ModelHandler:
25
  models = self.api.list_models(filter="vidore")
26
  repositories = [model.modelId for model in models] # type: ignore
27
 
28
- datasets_nickname = get_datasets_nickname()
29
  for repo_id in repositories:
30
- files = [f for f in self.api.list_repo_files(repo_id) if f.endswith('_metrics.json')]
 
 
31
  if len(files) == 0:
32
  continue
33
  else:
34
  for file in files:
35
- model_name = file.split('_metrics.json')[0]
 
 
 
36
 
37
  if model_name not in self.model_infos:
38
  readme_path = hf_hub_download(repo_id, filename="README.md")
@@ -51,7 +55,7 @@ class ModelHandler:
51
  print(f"Error loading {model_name} - {e}")
52
  continue
53
 
54
- #self._save_model_infos()
55
 
56
  model_res = {}
57
  if len(self.model_infos) > 0:
@@ -59,12 +63,17 @@ class ModelHandler:
59
  res = self.model_infos[model]["results"]
60
  dataset_res = {}
61
  for dataset in res.keys():
62
- if "validation_set" == dataset:
 
 
63
  continue
64
- dataset_res[datasets_nickname[dataset]] = res[dataset][metric]
 
 
65
  model_res[model] = dataset_res
66
 
67
  df = pd.DataFrame(model_res).T
 
68
  return df
69
  return pd.DataFrame()
70
 
@@ -88,7 +97,10 @@ class ModelHandler:
88
  df.insert(len(df.columns) - len(cols_to_rank), "Average", df[cols_to_rank].mean(axis=1, skipna=False))
89
  df.sort_values("Average", ascending=False, inplace=True)
90
  df.insert(0, "Rank", list(range(1, len(df) + 1)))
91
- df = df.round(2)
 
 
 
92
  # Fill NaN after averaging
93
  df.fillna("", inplace=True)
94
  return df
 
3
  from typing import Dict
4
  from huggingface_hub import HfApi, hf_hub_download, metadata_load
5
  import pandas as pd
6
+ from .dataset_handler import get_datasets_nickname, VIDORE_DATASETS_KEYWORDS
7
 
8
  class ModelHandler:
9
  def __init__(self, model_infos_path="model_infos.json"):
 
25
  models = self.api.list_models(filter="vidore")
26
  repositories = [model.modelId for model in models] # type: ignore
27
 
 
28
  for repo_id in repositories:
29
+ files = [f for f in self.api.list_repo_files(repo_id) if f.endswith('_metrics.json') or f == 'results.json']
30
+
31
+
32
  if len(files) == 0:
33
  continue
34
  else:
35
  for file in files:
36
+ if file.endswith('results.json'):
37
+ model_name = repo_id.replace('/', '_')
38
+ else:
39
+ model_name = file.split('_metrics.json')[0]
40
 
41
  if model_name not in self.model_infos:
42
  readme_path = hf_hub_download(repo_id, filename="README.md")
 
55
  print(f"Error loading {model_name} - {e}")
56
  continue
57
 
58
+ self._save_model_infos()
59
 
60
  model_res = {}
61
  if len(self.model_infos) > 0:
 
63
  res = self.model_infos[model]["results"]
64
  dataset_res = {}
65
  for dataset in res.keys():
66
+ #for each keyword check if it is in the dataset name if not continue
67
+ if not any(keyword in dataset for keyword in VIDORE_DATASETS_KEYWORDS):
68
+ print(f"{dataset} not found in ViDoRe datasets. Skipping ...")
69
  continue
70
+
71
+ dataset_nickname = get_datasets_nickname(dataset)
72
+ dataset_res[dataset_nickname] = res[dataset][metric]
73
  model_res[model] = dataset_res
74
 
75
  df = pd.DataFrame(model_res).T
76
+
77
  return df
78
  return pd.DataFrame()
79
 
 
97
  df.insert(len(df.columns) - len(cols_to_rank), "Average", df[cols_to_rank].mean(axis=1, skipna=False))
98
  df.sort_values("Average", ascending=False, inplace=True)
99
  df.insert(0, "Rank", list(range(1, len(df) + 1)))
100
+ #multiply values by 100 if they are floats and round to 1 decimal place
101
+ for col in df.columns:
102
+ if df[col].dtype == "float64":
103
+ df[col] = df[col].apply(lambda x: round(x * 100, 1))
104
  # Fill NaN after averaging
105
  df.fillna("", inplace=True)
106
  return df