File size: 5,369 Bytes
cfe9dd5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
"""TODO(arc): Add a description here."""
import json
import os
import datasets
# TODO(ai2_arc): BibTeX citation
_CITATION = """\
@article{allenai:arc,
author = {Peter Clark and Isaac Cowhey and Oren Etzioni and Tushar Khot and
Ashish Sabharwal and Carissa Schoenick and Oyvind Tafjord},
title = {Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challenge},
journal = {arXiv:1803.05457v1},
year = {2018},
}
"""
# TODO(ai2_arc):
_DESCRIPTION = """\
A new dataset of 7,787 genuine grade-school level, multiple-choice science questions, assembled to encourage research in
advanced question-answering. The dataset is partitioned into a Challenge Set and an Easy Set, where the former contains
only questions answered incorrectly by both a retrieval-based algorithm and a word co-occurrence algorithm. We are also
including a corpus of over 14 million science sentences relevant to the task, and an implementation of three neural baseline models for this dataset. We pose ARC as a challenge to the community.
"""
_URL = "https://s3-us-west-2.amazonaws.com/ai2-website/data/ARC-V1-Feb2018.zip"
class Ai2ArcConfig(datasets.BuilderConfig):
"""BuilderConfig for Ai2ARC."""
def __init__(self, **kwargs):
"""BuilderConfig for Ai2Arc.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(Ai2ArcConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
class Ai2Arc(datasets.GeneratorBasedBuilder):
"""TODO(arc): Short description of my dataset."""
# TODO(arc): Set up version.
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
Ai2ArcConfig(
name="ARC-Challenge",
description="""\
Challenge Set of 2590 “hard” questions (those that both a retrieval and a co-occurrence method fail to answer correctly)
""",
),
Ai2ArcConfig(
name="ARC-Easy",
description="""\
Easy Set of 5197 questions
""",
),
]
def _info(self):
# TODO(ai2_arc): Specifies the datasets.DatasetInfo object
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# datasets.features.FeatureConnectors
features=datasets.Features(
{
"id": datasets.Value("string"),
"question": datasets.Value("string"),
"choices": datasets.features.Sequence(
{"text": datasets.Value("string"), "label": datasets.Value("string")}
),
"answerKey": datasets.Value("string")
# These are the features of your dataset like images, labels ...
}
),
# If there's a common (input, target) tuple from the features,
# specify them here. They'll be used if as_supervised=True in
# builder.as_dataset.
supervised_keys=None,
# Homepage of the dataset for documentation
homepage="https://allenai.org/data/arc",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
# TODO(ai2_arc): Downloads the data and defines the splits
# dl_manager is a datasets.download.DownloadManager that can be used to
# download and extract URLs
dl_dir = dl_manager.download_and_extract(_URL)
data_dir = os.path.join(dl_dir, "ARC-V1-Feb2018-2")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={"filepath": os.path.join(data_dir, self.config.name, self.config.name + "-Train.jsonl")},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={"filepath": os.path.join(data_dir, self.config.name, self.config.name + "-Test.jsonl")},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={"filepath": os.path.join(data_dir, self.config.name, self.config.name + "-Dev.jsonl")},
),
]
def _generate_examples(self, filepath):
"""Yields examples."""
# TODO(ai2_arc): Yields (key, example) tuples from the dataset
with open(filepath, encoding="utf-8") as f:
for row in f:
data = json.loads(row)
answerkey = data["answerKey"]
id_ = data["id"]
question = data["question"]["stem"]
choices = data["question"]["choices"]
text_choices = [choice["text"] for choice in choices]
label_choices = [choice["label"] for choice in choices]
yield id_, {
"id": id_,
"answerKey": answerkey,
"question": question,
"choices": {"text": text_choices, "label": label_choices},
}
|