import os from datasets import load_dataset os.makedirs('./reference_files', exist_ok=True) for split in ['validation', 'test']: dataset = load_dataset('asahi417/qg_newsqa', '', split=split) for data in ['question', 'answer', 'sentence', 'paragraph']: with open('./reference_files/{}-{}.txt'.format(data, split), 'w') as f: if data == 'paragraph': f.write('\n'.join(dataset['paragraph_id'])) else: f.write('\n'.join(dataset[data]))