|
"""RedditQG: Reddit Question Generation Dataset.""" |
|
|
|
|
|
import json |
|
|
|
import datasets |
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{cao-wang-2021-controllable, |
|
title = "Controllable Open-ended Question Generation with A New Question Type Ontology", |
|
author = "Cao, Shuyang and |
|
Wang, Lu", |
|
booktitle = "Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)", |
|
month = aug, |
|
year = "2021", |
|
address = "Online", |
|
publisher = "Association for Computational Linguistics", |
|
url = "https://aclanthology.org/2021.acl-long.502", |
|
doi = "10.18653/v1/2021.acl-long.502", |
|
pages = "6424--6439", |
|
abstract = "We investigate the less-explored task of generating open-ended questions that are typically answered by multiple sentences. We first define a new question type ontology which differentiates the nuanced nature of questions better than widely used question words. A new dataset with 4,959 questions is labeled based on the new ontology. We then propose a novel question type-aware question generation framework, augmented by a semantic graph representation, to jointly predict question focuses and produce the question. Based on this framework, we further use both exemplars and automatically generated templates to improve controllability and diversity. Experiments on two newly collected large-scale datasets show that our model improves question quality over competitive comparisons based on automatic metrics. Human judges also rate our model outputs highly in answerability, coverage of scope, and overall quality. Finally, our model variants with templates can produce questions with enhanced controllability and diversity.", |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Reddit question generation dataset. |
|
""" |
|
|
|
_URL = "https://huggingface.co/datasets/launch/reddit_qg/resolve/main/data/" |
|
_URLS = { |
|
"train": _URL + "train.jsonl", |
|
"valid": _URL + "valid.jsonl", |
|
"test": _URL + "test.jsonl", |
|
} |
|
|
|
|
|
class RedditQG(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.0.0") |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"qid": datasets.Value("string"), |
|
"question": datasets.Value("string"), |
|
"answer": datasets.Value("string"), |
|
"score": datasets.Value("int32") |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=("answer", "question"), |
|
homepage="", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_files = dl_manager.download_and_extract(_URLS) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"split_file": downloaded_files["train"]}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"split_file": downloaded_files["valid"]}), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"split_file": downloaded_files["test"]}), |
|
] |
|
|
|
def _generate_examples(self, split_file): |
|
"""This function returns the examples in the raw (text) form.""" |
|
logger.info(f"generating examples from = {split_file}") |
|
|
|
with open(split_file) as f: |
|
for line in f: |
|
data = json.loads(line) |
|
yield data["id"], data |
|
|