| import re | |
| from datasets import load_dataset, Dataset, DatasetDict | |
| def main(): | |
| for config in ['high', 'middle']: | |
| datasets = load_dataset('ehovy/race', config) | |
| _datasets = {} | |
| for split in ['train', 'validation', 'test']: | |
| data = [] | |
| for example in datasets[split]: | |
| context = str(example['article']) | |
| question = str(example['question']) | |
| choices = example['options'] | |
| answer = example['answer'] | |
| answer_index = ord(answer) - ord('A') | |
| data.append({ | |
| 'context': context.strip(), | |
| 'question': question.strip(), | |
| 'choices': choices, | |
| 'answer': answer.strip(), | |
| 'answer_index': answer_index | |
| }) | |
| dataset = Dataset.from_list(data) | |
| _datasets[split] = dataset | |
| datasets = DatasetDict({ | |
| 'train': _datasets['train'], | |
| 'validation': _datasets['validation'], | |
| 'test': _datasets['test'], | |
| }) | |
| datasets.push_to_hub('extraordinarylab/race', config) | |
| if __name__ == '__main__': | |
| main() |