forked from ntu-adl-ta/ADL21-HW3
-
Notifications
You must be signed in to change notification settings - Fork 11
/
eval.py
31 lines (23 loc) · 795 Bytes
/
eval.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
import json
import argparse
from tw_rouge import get_rouge
def main(args):
refs, preds = {}, {}
with open(args.reference) as file:
for line in file:
line = json.loads(line)
refs[line['id']] = line['title'].strip() + '\n'
with open(args.submission) as file:
for line in file:
line = json.loads(line)
preds[line['id']] = line['title'].strip() + '\n'
keys = refs.keys()
refs = [refs[key] for key in keys]
preds = [preds[key] for key in keys]
print(json.dumps(get_rouge(preds, refs), indent=2))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--reference')
parser.add_argument('-s', '--submission')
args = parser.parse_args()
main(args)