patrickvonplaten commited on
Commit
8186dd3
1 Parent(s): ef16ac0
Files changed (2) hide show
  1. app.py +164 -0
  2. load_all_model_info.py +0 -93
app.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from huggingface_hub import HfApi, hf_hub_download
3
+ from huggingface_hub.repocard import metadata_load
4
+
5
+ import pandas as pd
6
+ import gradio as gr
7
+
8
+ METRICS_TO_NOT_DISPLAY = set(["ser"])
9
+ NO_LANGUAGE_MODELS = []
10
+
11
+ api = HfApi()
12
+ models = api.list_models(filter="robust-speech-event")
13
+ model_ids = [x.modelId for x in models]
14
+
15
+
16
+ def get_metadatas(model_ids):
17
+ metadatas = {}
18
+ for model_id in model_ids:
19
+ readme_path = hf_hub_download(model_id, filename="README.md")
20
+ metadatas[model_id] = metadata_load(readme_path)
21
+ return metadatas
22
+
23
+
24
+ def get_model_results_and_language_map(metadatas):
25
+ all_model_results = {}
26
+ # model_id
27
+ # - dataset
28
+ # - metric
29
+ model_language_map = {}
30
+ # model_id: lang
31
+ for model_id, metadata in metadatas.items():
32
+ if "language" not in metadata:
33
+ NO_LANGUAGE_MODELS.append(model_id)
34
+ continue
35
+ lang = metadata["language"]
36
+ model_language_map[model_id] = lang if isinstance(lang, list) else [lang]
37
+ if "model-index" not in metadata:
38
+ all_model_results[model_id] = None
39
+ else:
40
+ result_dict = {}
41
+ for result in metadata["model-index"][0]["results"]:
42
+ dataset = result["dataset"]["type"]
43
+ metrics = [x["type"] for x in result["metrics"]]
44
+ values = [
45
+ x["value"] if "value" in x else None for x in result["metrics"]
46
+ ]
47
+ result_dict[dataset] = {k: v for k, v in zip(metrics, values)}
48
+
49
+ all_model_results[model_id] = result_dict
50
+ return all_model_results, model_language_map
51
+
52
+
53
+ def get_datasets_metrics_langs(all_model_results, model_language_map):
54
+ # get all datasets
55
+ all_datasets = set(
56
+ sum([list(x.keys()) for x in all_model_results.values() if x is not None], [])
57
+ )
58
+ all_langs = set(sum(list(model_language_map.values()), []))
59
+
60
+ # get all metrics
61
+ all_metrics = []
62
+ for metric_result in all_model_results.values():
63
+ if metric_result is not None:
64
+ all_metrics += sum([list(x.keys()) for x in metric_result.values()], [])
65
+
66
+ all_metrics = set(all_metrics) - METRICS_TO_NOT_DISPLAY
67
+ return all_datasets, all_langs, all_metrics
68
+
69
+
70
+ # get results table (one table for each dataset, metric)
71
+ def retrieve_dataframes(
72
+ all_model_results, model_language_map, all_datasets, all_langs, all_metrics
73
+ ):
74
+ all_datasets_results = {}
75
+ pandas_datasets = {}
76
+ for dataset in all_datasets:
77
+ all_datasets_results[dataset] = {}
78
+ pandas_datasets[dataset] = {}
79
+ for metric in all_metrics:
80
+ all_datasets_results[dataset][metric] = {}
81
+ pandas_datasets[dataset][metric] = {}
82
+ for lang in all_langs:
83
+ all_datasets_results[dataset][metric][lang] = {}
84
+ results = {}
85
+ for model_id, model_result in all_model_results.items():
86
+ is_relevant = (
87
+ lang in model_language_map[model_id]
88
+ and model_result is not None
89
+ and dataset in model_result
90
+ and metric in model_result[dataset]
91
+ )
92
+ if not is_relevant:
93
+ continue
94
+
95
+ result = model_result[dataset][metric]
96
+ if isinstance(result, str):
97
+ "".join(result.split("%"))
98
+ try:
99
+ result = float(result)
100
+ except: # noqa: E722
101
+ result = None
102
+ elif isinstance(result, float) and result < 1.0:
103
+ # assuming that WER is given in 0.13 format
104
+ result = 100 * result
105
+ results[model_id] = round(result, 2) if result is not None else None
106
+
107
+ results = dict(
108
+ sorted(results.items(), key=lambda item: (item[1] is None, item[1]))
109
+ )
110
+ all_datasets_results[dataset][metric][lang] = [
111
+ f"{k}: {v}" for k, v in results.items()
112
+ ]
113
+
114
+ data = all_datasets_results[dataset][metric]
115
+ data_frame = pd.DataFrame.from_dict(data, orient="index")
116
+ data_frame.fillna("", inplace=True)
117
+ pandas_datasets[dataset][metric] = data_frame
118
+ return pandas_datasets
119
+
120
+
121
+ # 1. Retrieve metadatas
122
+ metadatas = get_metadatas(model_ids)
123
+
124
+ # 2. Parse to results
125
+ all_model_results, model_language_map = get_model_results_and_language_map(metadatas)
126
+
127
+ # 3. Get datasets and langs
128
+ all_datasets, all_langs, all_metrics = get_datasets_metrics_langs(
129
+ all_model_results, model_language_map
130
+ )
131
+
132
+ # 4. Get dataframes
133
+ all_dataframes = retrieve_dataframes(
134
+ all_model_results, model_language_map, all_datasets, all_langs, all_metrics
135
+ )
136
+
137
+
138
+ def select(dataset, metric):
139
+ return all_dataframes[dataset][metric]
140
+
141
+
142
+ iface = gr.Interface(
143
+ select,
144
+ [
145
+ gr.inputs.Dropdown(
146
+ list(all_datasets),
147
+ type="value",
148
+ default="mozilla-foundation/common_voice_7_0",
149
+ label="dataset",
150
+ ),
151
+ gr.inputs.Dropdown(
152
+ list(all_metrics), type="value", default="wer", label="metric"
153
+ ),
154
+ ],
155
+ "pandas",
156
+ examples=[
157
+ ["mozilla-foundation/common_voice_7_0", "wer"],
158
+ ["mozilla-foundation/common_voice_7_0", "cer"],
159
+ ],
160
+ )
161
+
162
+ iface.test_launch()
163
+
164
+ iface.launch()
load_all_model_info.py DELETED
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env python3
2
- from huggingface_hub import HfApi, hf_hub_download
3
- from huggingface_hub.repocard import metadata_load
4
-
5
- import pandas as pd
6
-
7
- METRICS_TO_NOT_DISPLAY = set(["ser"])
8
- NO_LANGUAGE_MODELS = []
9
-
10
- api = HfApi()
11
- models = api.list_models(filter="robust-speech-event")
12
-
13
- model_ids = [x.modelId for x in models]
14
-
15
- metadatas = {}
16
-
17
- for model_id in model_ids:
18
- readme_path = hf_hub_download(model_id, filename="README.md")
19
- metadatas[model_id] = metadata_load(readme_path)
20
-
21
-
22
- all_model_results = {}
23
- # model_id
24
- # - dataset
25
- # - metric
26
- model_language_map = {}
27
- # model_id: lang
28
- for model_id, metadata in metadatas.items():
29
- if "language" not in metadata:
30
- NO_LANGUAGE_MODELS.append(model_id)
31
- continue
32
- lang = metadata["language"]
33
- model_language_map[model_id] = lang if isinstance(lang, list) else [lang]
34
- if "model-index" not in metadata:
35
- all_model_results[model_id] = None
36
- else:
37
- result_dict = {}
38
- for result in metadata["model-index"][0]["results"]:
39
- dataset = result["dataset"]["type"]
40
- metrics = [x["type"] for x in result["metrics"]]
41
- values = [x["value"] if "value" in x else None for x in result["metrics"]]
42
- result_dict[dataset] = {k: v for k, v in zip(metrics, values)}
43
-
44
- all_model_results[model_id] = result_dict
45
-
46
- # get all datasets
47
- all_datasets = set(sum([list(x.keys()) for x in all_model_results.values() if x is not None], []))
48
- all_langs = set(sum(list(model_language_map.values()), []))
49
-
50
- # get all metrics
51
- all_metrics = []
52
- for metric_result in all_model_results.values():
53
- if metric_result is not None:
54
- all_metrics += sum([list(x.keys()) for x in metric_result.values()], [])
55
-
56
- all_metrics = set(all_metrics) - METRICS_TO_NOT_DISPLAY
57
-
58
- # get results table (one table for each dataset, metric)
59
- all_datasets_results = {}
60
- pandas_datasets = {}
61
- for dataset in all_datasets:
62
- all_datasets_results[dataset] = {}
63
- pandas_datasets[dataset] = {}
64
- for metric in all_metrics:
65
- all_datasets_results[dataset][metric] = {}
66
- pandas_datasets[dataset][metric] = {}
67
- for lang in all_langs:
68
- all_datasets_results[dataset][metric][lang] = {}
69
- results = {}
70
- for model_id, model_result in all_model_results.items():
71
- is_relevant = lang in model_language_map[model_id] and model_result is not None and dataset in model_result and metric in model_result[dataset]
72
- if not is_relevant:
73
- continue
74
-
75
- result = model_result[dataset][metric]
76
- if isinstance(result, str):
77
- "".join(result.split("%"))
78
- try:
79
- result = float(result)
80
- except:
81
- result = None
82
- elif isinstance(result, float) and result < 1.0:
83
- # assuming that WER is given in 0.13 format
84
- result = 100 * result
85
- results[model_id] = round(result, 2) if result is not None else None
86
-
87
- results = dict(sorted(results.items(), key=lambda item: (item[1] is None, item[1])))
88
- all_datasets_results[dataset][metric][lang] = [f"{k}: {v}" for k, v in results.items()]
89
-
90
- data = all_datasets_results[dataset][metric]
91
- data_frame = pd.DataFrame.from_dict(data, orient="index")
92
- data_frame.fillna("", inplace=True)
93
- pandas_datasets[dataset][metric] = data_frame