Create strategy-qa.py
Browse files- strategy-qa.py +85 -0
strategy-qa.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
import datasets
|
15 |
+
import json
|
16 |
+
|
17 |
+
_CITATION = """
|
18 |
+
|
19 |
+
"""
|
20 |
+
|
21 |
+
_DESCRIPTION = """
|
22 |
+
"""
|
23 |
+
|
24 |
+
_HOMEPAGE = ""
|
25 |
+
|
26 |
+
# TODO: Add the licence for the dataset here if you can find it
|
27 |
+
_LICENSE = ""
|
28 |
+
|
29 |
+
_URLS = {
|
30 |
+
"test": "https://github.com/wicsaax/strategy-qa/blob/main/strategyQA_train.json",
|
31 |
+
}
|
32 |
+
|
33 |
+
|
34 |
+
class strategyQA(datasets.GeneratorBasedBuilder):
|
35 |
+
|
36 |
+
|
37 |
+
VERSION = datasets.Version("0.0.1")
|
38 |
+
|
39 |
+
BUILDER_CONFIGS = [
|
40 |
+
datasets.BuilderConfig(
|
41 |
+
name="strategyQA", version=VERSION, description="Chinese dataset."
|
42 |
+
),
|
43 |
+
]
|
44 |
+
|
45 |
+
def _info(self):
|
46 |
+
features = datasets.Features(
|
47 |
+
{
|
48 |
+
"qid": datasets.Value("string"),
|
49 |
+
"term": datasets.Value("string"),
|
50 |
+
"description": datasets.Value("string"),
|
51 |
+
"question": datasets.Value("string"),
|
52 |
+
"answer": datasets.Value("bool"),
|
53 |
+
"facts": datasets.features.Sequence(datasets.Value("string"))
|
54 |
+
"decomposition": datasets.features.Sequence(datasets.Value("string"))
|
55 |
+
}
|
56 |
+
)
|
57 |
+
return datasets.DatasetInfo(
|
58 |
+
description=_DESCRIPTION,
|
59 |
+
features=features,
|
60 |
+
homepage=_HOMEPAGE,
|
61 |
+
license=_LICENSE,
|
62 |
+
citation=_CITATION,
|
63 |
+
)
|
64 |
+
|
65 |
+
def _split_generators(self, dl_manager):
|
66 |
+
urls = {
|
67 |
+
"test": _URLS["test"]
|
68 |
+
}
|
69 |
+
data_dir = dl_manager.download_and_extract(urls)
|
70 |
+
return [
|
71 |
+
datasets.SplitGenerator(
|
72 |
+
name=datasets.Split.TEST,
|
73 |
+
# These kwargs will be passed to _generate_examples
|
74 |
+
gen_kwargs={"filepath": data_dir["test"], "split": "test"},
|
75 |
+
)
|
76 |
+
]
|
77 |
+
|
78 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
79 |
+
def _generate_examples(self, filepath, split):
|
80 |
+
|
81 |
+
with open(filepath, encoding="utf-8") as f:
|
82 |
+
data = json.loads(f.read())
|
83 |
+
for article_idx,single_data in enumerate(data):
|
84 |
+
|
85 |
+
yield f"{article_idx}_{i}", single_data
|