from datasets import DatasetInfo, SplitGenerator, ClassLabel, Sequence, Split, GeneratorBasedBuilder from datasets.features import Features, Value import json class WikiHowNFQADataset(GeneratorBasedBuilder): VERSION = "1.0.0" def _info(self): features = Features({ 'article_id': Value('int32'), 'question': Value('string'), 'answer': Value('string'), 'related_document_urls_wayback_snapshots': Sequence(Value('string')), 'split': ClassLabel(names=['train', 'valid', 'test']), 'cluster': Value('int32'), }) return DatasetInfo( description="WikiHowNFQA dataset", features=features, homepage="https://huggingface.co/datasets/Lurunchik/WikiHowNFQA", citation="""@inproceedings{bolotova2023wikihowqa, title={WikiHowQA: A Comprehensive Benchmark for Multi-Document Non-Factoid Question Answering}, author={Bolotova, Valeriia and Blinov, Vladislav and Filippova, Sofya and Scholer, Falk and Sanderson, Mark}, booktitle="Proceedings of the 61th Conference of the Association for Computational Linguistics", year={2023} }""" ) def _split_generators(self, dl_manager): """Returns SplitGenerators.""" downloaded_file = dl_manager.download_and_extract('https://huggingface.co/datasets/Lurunchik/WikiHowNFQA/resolve/main/WikiHowNFQA.jsonl') return [ SplitGenerator( name=Split.TRAIN, gen_kwargs={ "filepath": downloaded_file, "split": "train", }, ), SplitGenerator( name=Split.VALIDATION, gen_kwargs={ "filepath": downloaded_file, "split": "valid", }, ), SplitGenerator( name=Split.TEST, gen_kwargs={ "filepath": downloaded_file, "split": "test", }, ), ] def _generate_examples(self, filepath, split): with open(filepath, encoding="utf-8") as f: for id_, line in enumerate(f): data = json.loads(line) if data['split'] == split: yield id_, { 'article_id': data['article_id'], 'question': data['question'], 'answer': data['answer'], 'related_document_urls_wayback_snapshots': data['related_document_urls_wayback_snapshots'], 'split': data['split'], 'cluster': data['cluster'], } WikiHowNFQADataset().download_and_prepare()