-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval_100.py
More file actions
30 lines (23 loc) · 920 Bytes
/
eval_100.py
File metadata and controls
30 lines (23 loc) · 920 Bytes
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
import json
import os
from utils.data import load_data_100
from eval import eval_f1
def main(args):
data_all = load_data_100()
valid_ids = set()
for item in data_all:
valid_ids.add(item['id'])
pred_file = os.path.join(args.result_dir, 'pred.jsonl')
assert os.path.exists(pred_file), f"Pred file {pred_file} does not exist"
with open(pred_file, 'r', encoding='utf-8') as f:
all_outputs = [json.loads(line) for line in f]
# Only keep entries whose IDs are in data_all
outputs = [item for item in all_outputs if item['id'] in valid_ids]
print(f"Filtered outputs: {len(outputs)} out of {len(all_outputs)} entries kept")
eval_f1(outputs)
if __name__ == "__main__":
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("--result_dir", type=str, required=True)
args = parser.parse_args()
main(args)