|
"""TODO(wiqa): Add a description here.""" |
|
|
|
|
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@article{wiqa, |
|
author = {Niket Tandon and Bhavana Dalvi Mishra and Keisuke Sakaguchi and Antoine Bosselut and Peter Clark} |
|
title = {WIQA: A dataset for "What if..." reasoning over procedural text}, |
|
journal = {arXiv:1909.04739v1}, |
|
year = {2019}, |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
The WIQA dataset V1 has 39705 questions containing a perturbation and a possible effect in the context of a paragraph. |
|
The dataset is split into 29808 train questions, 6894 dev questions and 3003 test questions. |
|
""" |
|
_URL = "https://public-aristo-processes.s3-us-west-2.amazonaws.com/wiqa_dataset_no_explanation_v2/wiqa-dataset-v2-october-2019.zip" |
|
URl = "s3://ai2-s2-research-public/open-corpus/2020-04-10/" |
|
|
|
|
|
class Wiqa(datasets.GeneratorBasedBuilder): |
|
"""TODO(wiqa): Short description of my dataset.""" |
|
|
|
|
|
VERSION = datasets.Version("0.1.0") |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
|
|
"question_stem": datasets.Value("string"), |
|
"question_para_step": datasets.features.Sequence(datasets.Value("string")), |
|
"answer_label": datasets.Value("string"), |
|
"answer_label_as_choice": datasets.Value("string"), |
|
"choices": datasets.features.Sequence( |
|
{"text": datasets.Value("string"), "label": datasets.Value("string")} |
|
), |
|
"metadata_question_id": datasets.Value("string"), |
|
"metadata_graph_id": datasets.Value("string"), |
|
"metadata_para_id": datasets.Value("string"), |
|
"metadata_question_type": datasets.Value("string"), |
|
"metadata_path_len": datasets.Value("int32"), |
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage="https://allenai.org/data/wiqa", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
dl_dir = dl_manager.download_and_extract(_URL) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={"filepath": os.path.join(dl_dir, "train.jsonl")}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={"filepath": os.path.join(dl_dir, "test.jsonl")}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={"filepath": os.path.join(dl_dir, "dev.jsonl")}, |
|
), |
|
] |
|
|
|
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) |
|
|
|
yield id_, { |
|
"question_stem": data["question"]["stem"], |
|
"question_para_step": data["question"]["para_steps"], |
|
"answer_label": data["question"]["answer_label"], |
|
"answer_label_as_choice": data["question"]["answer_label_as_choice"], |
|
"choices": { |
|
"text": [choice["text"] for choice in data["question"]["choices"]], |
|
"label": [choice["label"] for choice in data["question"]["choices"]], |
|
}, |
|
"metadata_question_id": data["metadata"]["ques_id"], |
|
"metadata_graph_id": data["metadata"]["graph_id"], |
|
"metadata_para_id": data["metadata"]["para_id"], |
|
"metadata_question_type": data["metadata"]["question_type"], |
|
"metadata_path_len": data["metadata"]["path_len"], |
|
} |
|
|