-
Notifications
You must be signed in to change notification settings - Fork 3
/
fix_results.py
64 lines (57 loc) · 2.68 KB
/
fix_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Iterates over json results for custom fixes
Usage: python fix_results.py results_folder_path
"""
import glob
import json
import sys
import os
from mteb import MTEB
results_folder = sys.argv[1]
files = glob.glob(f'{results_folder.strip("/")}/*/*.json')
print("Found files: ", files)
for file_name in files:
with open(file_name, 'r', encoding='utf-8') as f:
results = json.load(f)
if "dataset_version" in results:
results.pop("dataset_version")
if "mteb_version" not in results:
results["mteb_version"] = "0.0.2"
if "mteb_dataset_name" not in results:
results["mteb_dataset_name"] = file_name.split("/")[-1].replace(".json", "")
if "dataset_revision" not in results:
print(file_name)
mteb_desc = (
MTEB(tasks=[file_name.split("/")[-1].replace(".json", "").replace("CQADupstackRetrieval", "CQADupstackAndroidRetrieval")])
.tasks[0]
.description
)
import huggingface_hub
if "hf_hub_name" in mteb_desc:
hf_hub_name = mteb_desc.get("hf_hub_name")
else:
hf_hub_name = "BeIR/" + mteb_desc.get("beir_name")
if "cqadupstack" in hf_hub_name:
hf_hub_name = "BeIR/cqadupstack-qrels"
results["dataset_revision"] = huggingface_hub.hf_api.dataset_info(hf_hub_name).sha
if "STS22" in file_name:
for split, split_results in results.items():
if isinstance(split_results, dict):
for metric, score in split_results.items():
if isinstance(score, dict):
for sub_metric, sub_score in score.items():
if isinstance(sub_score, dict):
for sub_sub_metric, sub_sub_score in sub_score.items():
results[split][metric][sub_metric][sub_sub_metric] = abs(sub_sub_score)
else:
results[split][metric][sub_metric] = abs(sub_score)
else:
results[split][metric] = abs(score)
results.setdefault(split, {})
# Merge MSMARCO dev & test split runs
elif "MSMARCO." in file_name and os.path.exists(file_name.replace("MSMARCO.", "MSMARCO-test.")):
with open(file_name.replace("MSMARCO.", "MSMARCO-test."), 'r', encoding='utf-8') as f:
results_test = json.load(f)
results["test"] = results_test["test"]
with open(file_name, 'w', encoding='utf-8') as f:
json.dump(results, f, indent=4)