yangwang825 commited on
Commit
40349b3
·
verified ·
1 Parent(s): 37731c5

Create prepare.py

Browse files
Files changed (1) hide show
  1. prepare.py +37 -0
prepare.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from datasets import load_dataset, Dataset, DatasetDict
3
+
4
+
5
+ def main():
6
+ for config in ['high', 'middle']:
7
+ datasets = load_dataset('ehovy/race', config)
8
+
9
+ _datasets = {}
10
+ for split in ['train', 'validation', 'test']:
11
+ data = []
12
+ for example in datasets[split]:
13
+ context = str(example['article'])
14
+ question = str(example['question'])
15
+ choices = example['options']
16
+ answer = example['answer']
17
+ answer_index = ord(answer) - ord('A')
18
+ data.append({
19
+ 'context': context.strip(),
20
+ 'question': question.strip(),
21
+ 'choices': choices,
22
+ 'answer': answer.strip(),
23
+ 'answer_index': answer_index
24
+ })
25
+ dataset = Dataset.from_list(data)
26
+ _datasets[split] = dataset
27
+
28
+ datasets = DatasetDict({
29
+ 'train': _datasets['train'],
30
+ 'validation': _datasets['validation'],
31
+ 'test': _datasets['test'],
32
+ })
33
+ datasets.push_to_hub('extraordinarylab/race', config)
34
+
35
+
36
+ if __name__ == '__main__':
37
+ main()