eduagarcia commited on
Commit
bbfe97c
1 Parent(s): fd4838e

Caches model cards and dim_seq_size while first intiating the leaderboard

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -151,7 +151,10 @@ def add_rank(df):
151
  df.fillna("", inplace=True)
152
  return df
153
 
154
- def get_mteb_data(tasks=["Clustering"], langs=[], datasets=[], fillna=True, add_emb_dim=True, task_to_metric=TASK_TO_METRIC, rank=True):
 
 
 
155
  api = API
156
  models = api.list_models(filter="mteb")
157
  # Initialize list to models that we cannot fetch metadata from
@@ -174,12 +177,15 @@ def get_mteb_data(tasks=["Clustering"], langs=[], datasets=[], fillna=True, add_
174
  res["Embedding Dimensions"] = EXTERNAL_MODEL_TO_DIM.get(model, "")
175
  res["Max Tokens"] = EXTERNAL_MODEL_TO_SEQLEN.get(model, "")
176
  df_list.append(res)
177
-
178
  for model in models:
179
  if model.modelId in MODELS_TO_SKIP: continue
180
- print("MODEL", model)
181
- readme_path = hf_hub_download(model.modelId, filename="README.md")
182
- meta = metadata_load(readme_path)
 
 
 
183
  if "model-index" not in meta:
184
  continue
185
  # meta['model-index'][0]["results"] is list of elements like:
@@ -211,9 +217,11 @@ def get_mteb_data(tasks=["Clustering"], langs=[], datasets=[], fillna=True, add_
211
  if add_emb_dim:
212
  try:
213
  # Fails on gated repos, so we only include scores for them
214
- out["Embedding Dimensions"], out["Max Tokens"], out["Model Size (Million Parameters)"], out["Memory Usage (GB, fp32)"] = get_dim_seq_size(model)
 
 
215
  except:
216
- pass
217
  df_list.append(out)
218
  if model.library_name == "sentence-transformers" or "sentence-transformers" in model.tags or "modules.json" in {file.rfilename for file in model.siblings}:
219
  SENTENCE_TRANSFORMERS_COMPATIBLE_MODELS.add(out["Model"])
@@ -231,7 +239,9 @@ def get_mteb_data(tasks=["Clustering"], langs=[], datasets=[], fillna=True, add_
231
  df.fillna("", inplace=True)
232
  return df
233
 
234
- def get_mteb_average(task_dict: dict):
 
 
235
  all_tasks = reduce(lambda x, y: x + y, task_dict.values())
236
  DATA_OVERALL = get_mteb_data(
237
  tasks=list(task_dict.keys()),
@@ -239,6 +249,7 @@ def get_mteb_average(task_dict: dict):
239
  fillna=False,
240
  add_emb_dim=True,
241
  rank=False,
 
242
  )
243
  # Debugging:
244
  # DATA_OVERALL.to_csv("overall.csv")
@@ -277,7 +288,7 @@ for board, board_config in BOARDS_CONFIG.items():
277
  "data_tasks": {}
278
  }
279
  if board_config["has_overall"]:
280
- data_overall, data_tasks = get_mteb_average(board_config["tasks"])
281
  boards_data[board]["data_overall"] = data_overall
282
  boards_data[board]["data_tasks"] = data_tasks
283
  all_data_tasks.extend(data_tasks.values())
@@ -287,7 +298,7 @@ for board, board_config in BOARDS_CONFIG.items():
287
  if len(task_category_list) > 1:
288
  columns.append("Average")
289
  print(board, task_category, task_category_list)
290
- data_task_category = get_mteb_data([task_category], [], task_category_list)[columns + task_category_list]
291
  boards_data[board]["data_tasks"][task_category] = data_task_category
292
  all_data_tasks.append(data_task_category)
293
 
 
151
  df.fillna("", inplace=True)
152
  return df
153
 
154
+ MODEL_CARD_METADATA = {}
155
+ MODEL_EMB_DIM = {}
156
+ def get_mteb_data(tasks=["Clustering"], langs=[], datasets=[], fillna=True, add_emb_dim=True, task_to_metric=TASK_TO_METRIC, rank=True, refresh=True):
157
+ global MODEL_CARD_METADATA, MODEL_EMB_DIM
158
  api = API
159
  models = api.list_models(filter="mteb")
160
  # Initialize list to models that we cannot fetch metadata from
 
177
  res["Embedding Dimensions"] = EXTERNAL_MODEL_TO_DIM.get(model, "")
178
  res["Max Tokens"] = EXTERNAL_MODEL_TO_SEQLEN.get(model, "")
179
  df_list.append(res)
180
+
181
  for model in models:
182
  if model.modelId in MODELS_TO_SKIP: continue
183
+ print("MODEL", model.modelId)
184
+ if model.modelId not in MODEL_CARD_METADATA or refresh:
185
+ readme_path = hf_hub_download(model.modelId, filename="README.md")
186
+ meta = metadata_load(readme_path)
187
+ MODEL_CARD_METADATA[model.modelId] = meta
188
+ meta = MODEL_CARD_METADATA[model.modelId]
189
  if "model-index" not in meta:
190
  continue
191
  # meta['model-index'][0]["results"] is list of elements like:
 
217
  if add_emb_dim:
218
  try:
219
  # Fails on gated repos, so we only include scores for them
220
+ if model.modelId not in MODEL_EMB_DIM or refresh:
221
+ MODEL_EMB_DIM[model.modelId] = get_dim_seq_size(model)
222
+ out["Embedding Dimensions"], out["Max Tokens"], out["Model Size (Million Parameters)"], out["Memory Usage (GB, fp32)"] = MODEL_EMB_DIM[model.modelId]
223
  except:
224
+ MODEL_EMB_DIM[model.modelId] = None, None, None, None
225
  df_list.append(out)
226
  if model.library_name == "sentence-transformers" or "sentence-transformers" in model.tags or "modules.json" in {file.rfilename for file in model.siblings}:
227
  SENTENCE_TRANSFORMERS_COMPATIBLE_MODELS.add(out["Model"])
 
239
  df.fillna("", inplace=True)
240
  return df
241
 
242
+ # Get dict with a task list for each task category
243
+ # E.g. {"Classification": ["AmazonMassiveIntentClassification (en)", ...], "PairClassification": ["SprintDuplicateQuestions", ...]}
244
+ def get_mteb_average(task_dict: dict, refresh=True):
245
  all_tasks = reduce(lambda x, y: x + y, task_dict.values())
246
  DATA_OVERALL = get_mteb_data(
247
  tasks=list(task_dict.keys()),
 
249
  fillna=False,
250
  add_emb_dim=True,
251
  rank=False,
252
+ refresh=refresh
253
  )
254
  # Debugging:
255
  # DATA_OVERALL.to_csv("overall.csv")
 
288
  "data_tasks": {}
289
  }
290
  if board_config["has_overall"]:
291
+ data_overall, data_tasks = get_mteb_average(board_config["tasks"], refresh=False)
292
  boards_data[board]["data_overall"] = data_overall
293
  boards_data[board]["data_tasks"] = data_tasks
294
  all_data_tasks.extend(data_tasks.values())
 
298
  if len(task_category_list) > 1:
299
  columns.append("Average")
300
  print(board, task_category, task_category_list)
301
+ data_task_category = get_mteb_data([task_category], [], task_category_list, refresh=False)[columns + task_category_list]
302
  boards_data[board]["data_tasks"][task_category] = data_task_category
303
  all_data_tasks.append(data_task_category)
304