yangwang825 commited on
Commit
935dc57
·
verified ·
1 Parent(s): 600e19c

Create prepare.py

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