-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_checker.py
78 lines (63 loc) · 2.02 KB
/
format_checker.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import argparse
import subprocess
from glob import glob
parser = argparse.ArgumentParser(description="Machine-generated text detection tool")
parser.add_argument(
"--submission-dir",
help="path to submission directory containing the jsonl files for submission",
default="./submission",
)
parser.add_argument(
"--organizer-repo-dir",
help="path to organizer repository directory",
default="./SemEval2024-task8",
)
def validate_dir(dir_path: str):
if not os.path.exists(dir_path):
raise ValueError(
f"Directory {dir_path} does not exist"
)
def get_submission_files(submission_dir: str):
return glob(os.path.join(submission_dir, "*.jsonl"))
def main():
args = parser.parse_args()
validate_dir(args.submission_dir)
validate_dir(args.organizer_repo_dir)
submission_files = get_submission_files(args.submission_dir)
for submission_file in submission_files:
subtask = None
if "subtask_a" in submission_file:
subtask = "subtaskA"
elif "subtask_b" in submission_file:
subtask = "subtaskB"
elif "subtask_c" in submission_file:
subtask = "subtaskC"
else:
raise ValueError(f"Unknown subtask for file {submission_file}")
format_checker_script_path = os.path.join(
args.organizer_repo_dir,
subtask,
"format_checker",
"format_checker.py"
)
print(f"Running format checker for file {submission_file}...\n")
try:
subprocess.run(
[
"python",
format_checker_script_path,
"--pred_files_path",
submission_file
],
check=True,
)
except Exception as ex:
print(
f"Format checker failed for file: {submission_file} "
f"with error: {ex}"
)
print()
print("-" * 20)
print()
main()