-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsplit.py
34 lines (26 loc) · 1.07 KB
/
split.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
"""Official split script for PI-SQuAD v0.1"""
import argparse
import json
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Official split script for PI-SQuAD v0.1')
parser.add_argument('data_path', help='Dataset file path')
parser.add_argument('context_path', help='Output path for context-only dataset')
parser.add_argument('question_path', help='Output path for question-only dataset')
args = parser.parse_args()
with open(args.data_path, 'r') as fp:
context = json.load(fp)
with open(args.data_path, 'r') as fp:
question = json.load(fp)
for article in context['data']:
for para in article['paragraphs']:
del para['qas']
for article in question['data']:
for para in article['paragraphs']:
del para['context']
for qa in para['qas']:
if 'answers' in qa:
del qa['answers']
with open(args.context_path, 'w') as fp:
json.dump(context, fp)
with open(args.question_path, 'w') as fp:
json.dump(question, fp)