-
Notifications
You must be signed in to change notification settings - Fork 0
/
glue_result_reader.py
59 lines (46 loc) · 1.81 KB
/
glue_result_reader.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
"""Reader the results generated by fine-tuning"""
import os
import shutil
import argparse
parser = argparse.ArgumentParser(description='')
parser.add_argument('--dir', dest='dir', default='', help='path of the fine-tuning results')
args = parser.parse_args()
if __name__ == '__main__':
if not os.path.exists(args.dir):
print("Dir error. ")
else:
# task_name --> standard task name
standard_file_name = {
"cola": "CoLA",
"mnlim": "MNLI-m",
"mnlimm": "MNLI-mm",
"mrpc": "MRPC",
"qnli": "QNLI",
"qqp": "QQP",
"rte": "RTE",
"sst2": "SST-2",
"stsb": "STS-B",
"wnli": "WNLI",
"ax": "AX"}
task_folders = []
root_dir = ""
for root, dirs, _ in os.walk(args.dir):
if root == args.dir:
root_dir = root
task_folders = dirs
break
task_folders = sorted([task_folder for task_folder in task_folders if task_folder != "submission"])
print("Root dir:", root_dir)
print("Task folders: ", task_folders)
for task_folder in task_folders:
task_name = task_folder.split('_')[0]
print("Current task: {}".format(task_name))
try:
if task_name != 'ax':
with open(os.path.join(root_dir, task_folder) + "/eval_results.txt", "r") as reader:
for line in reader.readlines():
print(line)
shutil.copyfile(os.path.join(root_dir, task_folder) + "/{}.tsv".format(standard_file_name[task_name]),
os.path.join(root_dir, "submission") + "/{}.tsv".format(standard_file_name[task_name]))
except:
continue