Commit
•
35e0625
1
Parent(s):
d972dc6
Delete loading script
Browse files
qasc.py
DELETED
@@ -1,123 +0,0 @@
|
|
1 |
-
"""TODO(qasc): Add a description here."""
|
2 |
-
|
3 |
-
|
4 |
-
import json
|
5 |
-
|
6 |
-
import datasets
|
7 |
-
|
8 |
-
|
9 |
-
# TODO(qasc): BibTeX citation
|
10 |
-
_CITATION = """\
|
11 |
-
@article{allenai:qasc,
|
12 |
-
author = {Tushar Khot and Peter Clark and Michal Guerquin and Peter Jansen and Ashish Sabharwal},
|
13 |
-
title = {QASC: A Dataset for Question Answering via Sentence Composition},
|
14 |
-
journal = {arXiv:1910.11473v2},
|
15 |
-
year = {2020},
|
16 |
-
}
|
17 |
-
"""
|
18 |
-
|
19 |
-
# TODO(qasc):
|
20 |
-
_DESCRIPTION = """
|
21 |
-
QASC is a question-answering dataset with a focus on sentence composition. It consists of 9,980 8-way multiple-choice
|
22 |
-
questions about grade school science (8,134 train, 926 dev, 920 test), and comes with a corpus of 17M sentences.
|
23 |
-
"""
|
24 |
-
_URl = "http://data.allenai.org/downloads/qasc/qasc_dataset.tar.gz"
|
25 |
-
|
26 |
-
|
27 |
-
class Qasc(datasets.GeneratorBasedBuilder):
|
28 |
-
"""TODO(qasc): Short description of my dataset."""
|
29 |
-
|
30 |
-
# TODO(qasc): Set up version.
|
31 |
-
VERSION = datasets.Version("0.1.0")
|
32 |
-
|
33 |
-
def _info(self):
|
34 |
-
# TODO(qasc): Specifies the datasets.DatasetInfo object
|
35 |
-
return datasets.DatasetInfo(
|
36 |
-
# This is the description that will appear on the datasets page.
|
37 |
-
description=_DESCRIPTION,
|
38 |
-
# datasets.features.FeatureConnectors
|
39 |
-
features=datasets.Features(
|
40 |
-
{
|
41 |
-
"id": datasets.Value("string"),
|
42 |
-
"question": datasets.Value("string"),
|
43 |
-
"choices": datasets.features.Sequence(
|
44 |
-
{"text": datasets.Value("string"), "label": datasets.Value("string")}
|
45 |
-
),
|
46 |
-
"answerKey": datasets.Value("string"),
|
47 |
-
"fact1": datasets.Value("string"),
|
48 |
-
"fact2": datasets.Value("string"),
|
49 |
-
"combinedfact": datasets.Value("string"),
|
50 |
-
"formatted_question": datasets.Value("string"),
|
51 |
-
# These are the features of your dataset like images, labels ...
|
52 |
-
}
|
53 |
-
),
|
54 |
-
# If there's a common (input, target) tuple from the features,
|
55 |
-
# specify them here. They'll be used if as_supervised=True in
|
56 |
-
# builder.as_dataset.
|
57 |
-
supervised_keys=None,
|
58 |
-
# Homepage of the dataset for documentation
|
59 |
-
homepage="https://allenai.org/data/qasc",
|
60 |
-
citation=_CITATION,
|
61 |
-
)
|
62 |
-
|
63 |
-
def _split_generators(self, dl_manager):
|
64 |
-
"""Returns SplitGenerators."""
|
65 |
-
# TODO(qasc): Downloads the data and defines the splits
|
66 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to
|
67 |
-
# download and extract URLs
|
68 |
-
archive = dl_manager.download(_URl)
|
69 |
-
return [
|
70 |
-
datasets.SplitGenerator(
|
71 |
-
name=datasets.Split.TRAIN,
|
72 |
-
# These kwargs will be passed to _generate_examples
|
73 |
-
gen_kwargs={
|
74 |
-
"filepath": "/".join(["QASC_Dataset", "train.jsonl"]),
|
75 |
-
"files": dl_manager.iter_archive(archive),
|
76 |
-
},
|
77 |
-
),
|
78 |
-
datasets.SplitGenerator(
|
79 |
-
name=datasets.Split.TEST,
|
80 |
-
# These kwargs will be passed to _generate_examples
|
81 |
-
gen_kwargs={
|
82 |
-
"filepath": "/".join(["QASC_Dataset", "test.jsonl"]),
|
83 |
-
"files": dl_manager.iter_archive(archive),
|
84 |
-
},
|
85 |
-
),
|
86 |
-
datasets.SplitGenerator(
|
87 |
-
name=datasets.Split.VALIDATION,
|
88 |
-
# These kwargs will be passed to _generate_examples
|
89 |
-
gen_kwargs={
|
90 |
-
"filepath": "/".join(["QASC_Dataset", "dev.jsonl"]),
|
91 |
-
"files": dl_manager.iter_archive(archive),
|
92 |
-
},
|
93 |
-
),
|
94 |
-
]
|
95 |
-
|
96 |
-
def _generate_examples(self, filepath, files):
|
97 |
-
"""Yields examples."""
|
98 |
-
# TODO(qasc): Yields (key, example) tuples from the dataset
|
99 |
-
for path, f in files:
|
100 |
-
if path == filepath:
|
101 |
-
for row in f:
|
102 |
-
data = json.loads(row.decode("utf-8"))
|
103 |
-
answerkey = data.get("answerKey", "")
|
104 |
-
id_ = data["id"]
|
105 |
-
question = data["question"]["stem"]
|
106 |
-
choices = data["question"]["choices"]
|
107 |
-
text_choices = [choice["text"] for choice in choices]
|
108 |
-
label_choices = [choice["label"] for choice in choices]
|
109 |
-
fact1 = data.get("fact1", "")
|
110 |
-
fact2 = data.get("fact2", "")
|
111 |
-
combined_fact = data.get("combinedfact", "")
|
112 |
-
formatted_question = data.get("formatted_question", "")
|
113 |
-
yield id_, {
|
114 |
-
"id": id_,
|
115 |
-
"answerKey": answerkey,
|
116 |
-
"question": question,
|
117 |
-
"choices": {"text": text_choices, "label": label_choices},
|
118 |
-
"fact1": fact1,
|
119 |
-
"fact2": fact2,
|
120 |
-
"combinedfact": combined_fact,
|
121 |
-
"formatted_question": formatted_question,
|
122 |
-
}
|
123 |
-
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|