|
|
|
|
|
import json |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{clark2019boolq, |
|
title = {BoolQ: Exploring the Surprising Difficulty of Natural Yes/No Questions}, |
|
author = {Clark, Christopher and Lee, Kenton and Chang, Ming-Wei, and Kwiatkowski, Tom and Collins, Michael, and Toutanova, Kristina}, |
|
booktitle = {NAACL}, |
|
year = {2019}, |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
BoolQ is a question answering dataset for yes/no questions containing 15942 examples. These questions are naturally |
|
occurring ---they are generated in unprompted and unconstrained settings. |
|
Each example is a triplet of (question, passage, answer), with the title of the page as optional additional context. |
|
The text-pair classification setup is similar to existing natural language inference tasks. |
|
""" |
|
|
|
_URL = "https://storage.googleapis.com/boolq/" |
|
_URLS = { |
|
"train": _URL + "train.jsonl", |
|
"dev": _URL + "dev.jsonl", |
|
} |
|
|
|
|
|
class Boolq(datasets.GeneratorBasedBuilder): |
|
"""TODO(boolq): Short description of my dataset.""" |
|
|
|
|
|
VERSION = datasets.Version("0.1.0") |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
"question": datasets.Value("string"), |
|
"answer": datasets.Value("bool"), |
|
"passage": datasets.Value("string") |
|
|
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage="https://github.com/google-research-datasets/boolean-questions", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
urls_to_download = _URLS |
|
downloaded_files = dl_manager.download(urls_to_download) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={"filepath": downloaded_files["dev"]}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""Yields examples.""" |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
for id_, row in enumerate(f): |
|
data = json.loads(row) |
|
question = data["question"] |
|
answer = data["answer"] |
|
passage = data["passage"] |
|
title = data["title"] |
|
yield id_, {"question": question, "answer": answer, "passage": passage, "title": title} |
|
|