-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformat_adversarial_annotations.py
More file actions
31 lines (25 loc) · 1.12 KB
/
format_adversarial_annotations.py
File metadata and controls
31 lines (25 loc) · 1.12 KB
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
output_fn = 'data/adversarial_annotations/adversarial_annotations.jsonl'
answer_fn = 'data/modified_annots/val_answer_shortcut/val_answer_shortcut.jsonl.new'
rationale_fn = 'data/modified_annots_rationale/val_answer_shortcut/val_answer_shortcut_rationale.jsonl.new'
def _read_jsonl_file(input_fn):
annots = []
with open(input_fn, 'r') as f:
for line in f:
annots.append(json.loads(line))
return annots
answer_annots = _read_jsonl_file(answer_fn)
rationale_annots = _read_jsonl_file(rationale_fn)
with open(output_fn, 'w') as f:
for answer_annot, rationale_annot in zip(answer_annots, rationale_annots):
assert answer_annot['annot_id'] == rationale_annot['annot_id']
annots = {
'annot_id': answer_annot['annot_id'],
'answer_label': answer_annot['label'],
'answer_tokens': answer_annot['result_tokens'],
'answer_losses': answer_annot['result_losses'],
'rationale_label': rationale_annot['label'],
'rationale_tokens': rationale_annot['result_tokens'],
'rationale_losses': rationale_annot['result_losses'],
}
f.write('%s\n' % json.dumps(annots))