| | import random |
| | from datasets import load_dataset, Dataset, DatasetDict |
| |
|
| |
|
| | def main(): |
| | datasets = load_dataset('allenai/qasc') |
| |
|
| | _datasets = {} |
| | for split in ['train', 'validation', 'test']: |
| | data = [] |
| | split_dataset = datasets[split] |
| |
|
| | for example in split_dataset: |
| | question = str(example['question']).strip() |
| | correct_answer = example['correct_answer'].strip() |
| | |
| | |
| | choices = [ |
| | example['distractor1'].strip(), |
| | example['distractor2'].strip(), |
| | example['distractor3'].strip(), |
| | correct_answer |
| | ] |
| | |
| | |
| | random.shuffle(choices) |
| | |
| | |
| | answer_index = choices.index(correct_answer) |
| | |
| | answer = chr(ord('A') + answer_index) |
| |
|
| | data.append({ |
| | 'question': question, |
| | 'choices': choices, |
| | 'answer': answer, |
| | 'answer_index': answer_index, |
| | 'support': example['support'], |
| | }) |
| |
|
| | _datasets[split] = Dataset.from_list(data) |
| | |
| | datasets = DatasetDict(_datasets) |
| |
|
| | datasets.push_to_hub('extraordinarylab/sciq') |
| |
|
| |
|
| | if __name__ == '__main__': |
| | main() |
| |
|