|
"""TODO(quarel): Add a description here.""" |
|
|
|
|
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{quarel_v1, |
|
title={QuaRel: A Dataset and Models for Answering Questions about Qualitative Relationships}, |
|
author={Oyvind Tafjord, Peter Clark, Matt Gardner, Wen-tau Yih, Ashish Sabharwal}, |
|
year={2018}, |
|
journal={arXiv:1805.05377v1} |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """ |
|
QuaRel is a crowdsourced dataset of 2771 multiple-choice story questions, including their logical forms. |
|
""" |
|
_URL = "https://s3-us-west-2.amazonaws.com/ai2-website/data/quarel-dataset-v1-nov2018.zip" |
|
|
|
|
|
class Quarel(datasets.GeneratorBasedBuilder): |
|
"""TODO(quarel): Short description of my dataset.""" |
|
|
|
|
|
VERSION = datasets.Version("0.1.0") |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
|
|
"id": datasets.Value("string"), |
|
"answer_index": datasets.Value("int32"), |
|
"logical_forms": datasets.features.Sequence(datasets.Value("string")), |
|
"logical_form_pretty": datasets.Value("string"), |
|
"world_literals": datasets.features.Sequence( |
|
{"world1": datasets.Value("string"), "world2": datasets.Value("string")} |
|
), |
|
"question": datasets.Value("string"), |
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage="https://allenai.org/data/quarel", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
dl_dir = dl_manager.download_and_extract(_URL) |
|
data_dir = os.path.join(dl_dir, "quarel-dataset-v1") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={"filepath": os.path.join(data_dir, "quarel-v1-train.jsonl")}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={"filepath": os.path.join(data_dir, "quarel-v1-test.jsonl")}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={"filepath": os.path.join(data_dir, "quarel-v1-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_, { |
|
"id": data["id"], |
|
"answer_index": data["answer_index"], |
|
"logical_forms": data["logical_forms"], |
|
"world_literals": { |
|
"world1": [data["world_literals"]["world1"]], |
|
"world2": [data["world_literals"]["world2"]], |
|
}, |
|
"logical_form_pretty": data["logical_form_pretty"], |
|
"question": data["question"], |
|
} |
|
|