Datasets:
Update JAQKET.py
Browse filesbump dataset version to 0.3.0
JAQKET.py
CHANGED
|
@@ -93,18 +93,26 @@ def dataset_info_v2() -> ds.Features:
|
|
| 93 |
)
|
| 94 |
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
class JAQKET(ds.GeneratorBasedBuilder):
|
| 97 |
-
VERSION = ds.Version("0.
|
| 98 |
BUILDER_CONFIGS = [
|
| 99 |
-
|
| 100 |
name="v1.0",
|
| 101 |
version=VERSION,
|
| 102 |
description=_DESCRIPTION_CONFIGS["v1.0"],
|
|
|
|
| 103 |
),
|
| 104 |
-
|
| 105 |
name="v2.0",
|
| 106 |
version=VERSION,
|
| 107 |
description=_DESCRIPTION_CONFIGS["v2.0"],
|
|
|
|
| 108 |
),
|
| 109 |
]
|
| 110 |
|
|
@@ -145,12 +153,14 @@ class JAQKET(ds.GeneratorBasedBuilder):
|
|
| 145 |
|
| 146 |
def _generate_examples_v1(
|
| 147 |
self,
|
| 148 |
-
file_path:
|
| 149 |
-
entities_file_path:
|
| 150 |
-
|
| 151 |
):
|
| 152 |
if file_path is None or entities_file_path is None:
|
| 153 |
raise ValueError(f"Invalid argument for {self.config.name}")
|
|
|
|
|
|
|
| 154 |
|
| 155 |
entities = dict()
|
| 156 |
with open(entities_file_path, "r", encoding="utf-8") as fin:
|
|
@@ -166,14 +176,14 @@ class JAQKET(ds.GeneratorBasedBuilder):
|
|
| 166 |
q_id = data_raw["qid"]
|
| 167 |
question = data_raw["question"].replace("_", "")
|
| 168 |
answer_entity = data_raw["answer_entity"]
|
| 169 |
-
answer_candidates = data_raw["answer_candidates"][:
|
| 170 |
|
| 171 |
if answer_entity not in answer_candidates:
|
| 172 |
continue
|
| 173 |
-
if len(answer_candidates) !=
|
| 174 |
continue
|
| 175 |
|
| 176 |
-
contexts = [entities[answer_candidates[i]] for i in range(
|
| 177 |
label = str(answer_candidates.index(answer_entity))
|
| 178 |
example_dict = {
|
| 179 |
"qid": q_id,
|
|
@@ -187,10 +197,13 @@ class JAQKET(ds.GeneratorBasedBuilder):
|
|
| 187 |
|
| 188 |
def _generate_examples_v2(
|
| 189 |
self,
|
| 190 |
-
file_path:
|
|
|
|
| 191 |
):
|
| 192 |
if file_path is None:
|
| 193 |
raise ValueError(f"Invalid argument for {self.config.name}")
|
|
|
|
|
|
|
| 194 |
|
| 195 |
with open(file_path, "r") as rf:
|
| 196 |
json_data = json.load(rf)
|
|
@@ -202,6 +215,11 @@ class JAQKET(ds.GeneratorBasedBuilder):
|
|
| 202 |
{"text": answer, "answer_start": -1 } # -1: dummy
|
| 203 |
for answer in json_dict["answers"]
|
| 204 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
ctxs = [
|
| 206 |
{
|
| 207 |
"id": ctx["id"],
|
|
@@ -211,7 +229,7 @@ class JAQKET(ds.GeneratorBasedBuilder):
|
|
| 211 |
"has_answer": ctx["has_answer"]
|
| 212 |
|
| 213 |
}
|
| 214 |
-
for ctx in json_dict["ctxs"]
|
| 215 |
]
|
| 216 |
example_dict = {
|
| 217 |
"qid": q_id,
|
|
@@ -223,13 +241,12 @@ class JAQKET(ds.GeneratorBasedBuilder):
|
|
| 223 |
|
| 224 |
def _generate_examples(
|
| 225 |
self,
|
| 226 |
-
file_path:
|
| 227 |
entities_file_path: Optional[str] = None,
|
| 228 |
-
num_candidates: int = 5,
|
| 229 |
):
|
| 230 |
if self.config.name == "v1.0":
|
| 231 |
-
yield from self._generate_examples_v1(file_path, entities_file_path,
|
| 232 |
elif self.config.name == "v2.0":
|
| 233 |
-
yield from self._generate_examples_v2(file_path)
|
| 234 |
else:
|
| 235 |
raise ValueError(f"Invalid config name: {self.config.name}")
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
|
| 96 |
+
class JAQKETBuilderConfig(ds.BuilderConfig):
|
| 97 |
+
def __init__(self, name, num_contexts, **kwargs):
|
| 98 |
+
super().__init__(name, **kwargs)
|
| 99 |
+
self.num_contexts = num_contexts
|
| 100 |
+
|
| 101 |
+
|
| 102 |
class JAQKET(ds.GeneratorBasedBuilder):
|
| 103 |
+
VERSION = ds.Version("0.3.0")
|
| 104 |
BUILDER_CONFIGS = [
|
| 105 |
+
JAQKETBuilderConfig(
|
| 106 |
name="v1.0",
|
| 107 |
version=VERSION,
|
| 108 |
description=_DESCRIPTION_CONFIGS["v1.0"],
|
| 109 |
+
num_contexts=5,
|
| 110 |
),
|
| 111 |
+
JAQKETBuilderConfig(
|
| 112 |
name="v2.0",
|
| 113 |
version=VERSION,
|
| 114 |
description=_DESCRIPTION_CONFIGS["v2.0"],
|
| 115 |
+
num_contexts=5,
|
| 116 |
),
|
| 117 |
]
|
| 118 |
|
|
|
|
| 153 |
|
| 154 |
def _generate_examples_v1(
|
| 155 |
self,
|
| 156 |
+
file_path: str,
|
| 157 |
+
entities_file_path: str,
|
| 158 |
+
num_contexts: int,
|
| 159 |
):
|
| 160 |
if file_path is None or entities_file_path is None:
|
| 161 |
raise ValueError(f"Invalid argument for {self.config.name}")
|
| 162 |
+
if num_contexts is None:
|
| 163 |
+
num_contexts = 20 # maximum
|
| 164 |
|
| 165 |
entities = dict()
|
| 166 |
with open(entities_file_path, "r", encoding="utf-8") as fin:
|
|
|
|
| 176 |
q_id = data_raw["qid"]
|
| 177 |
question = data_raw["question"].replace("_", "")
|
| 178 |
answer_entity = data_raw["answer_entity"]
|
| 179 |
+
answer_candidates = data_raw["answer_candidates"][:num_contexts]
|
| 180 |
|
| 181 |
if answer_entity not in answer_candidates:
|
| 182 |
continue
|
| 183 |
+
if len(answer_candidates) != num_contexts:
|
| 184 |
continue
|
| 185 |
|
| 186 |
+
contexts = [entities[answer_candidates[i]] for i in range(num_contexts)]
|
| 187 |
label = str(answer_candidates.index(answer_entity))
|
| 188 |
example_dict = {
|
| 189 |
"qid": q_id,
|
|
|
|
| 197 |
|
| 198 |
def _generate_examples_v2(
|
| 199 |
self,
|
| 200 |
+
file_path: str,
|
| 201 |
+
num_contexts: int,
|
| 202 |
):
|
| 203 |
if file_path is None:
|
| 204 |
raise ValueError(f"Invalid argument for {self.config.name}")
|
| 205 |
+
if num_contexts is None:
|
| 206 |
+
num_contexts = 100 # it's the largest in acc@k on https://github.com/cl-tohoku/AIO2_DPR_baseline
|
| 207 |
|
| 208 |
with open(file_path, "r") as rf:
|
| 209 |
json_data = json.load(rf)
|
|
|
|
| 215 |
{"text": answer, "answer_start": -1 } # -1: dummy
|
| 216 |
for answer in json_dict["answers"]
|
| 217 |
]
|
| 218 |
+
|
| 219 |
+
has_answer = [ctx["has_answer"] for ctx in json_dict["ctxs"][:num_contexts]]
|
| 220 |
+
if True not in has_answer:
|
| 221 |
+
continue
|
| 222 |
+
|
| 223 |
ctxs = [
|
| 224 |
{
|
| 225 |
"id": ctx["id"],
|
|
|
|
| 229 |
"has_answer": ctx["has_answer"]
|
| 230 |
|
| 231 |
}
|
| 232 |
+
for ctx in json_dict["ctxs"][:num_contexts]
|
| 233 |
]
|
| 234 |
example_dict = {
|
| 235 |
"qid": q_id,
|
|
|
|
| 241 |
|
| 242 |
def _generate_examples(
|
| 243 |
self,
|
| 244 |
+
file_path: str,
|
| 245 |
entities_file_path: Optional[str] = None,
|
|
|
|
| 246 |
):
|
| 247 |
if self.config.name == "v1.0":
|
| 248 |
+
yield from self._generate_examples_v1(file_path, entities_file_path, self.config.num_contexts)
|
| 249 |
elif self.config.name == "v2.0":
|
| 250 |
+
yield from self._generate_examples_v2(file_path, self.config.num_contexts)
|
| 251 |
else:
|
| 252 |
raise ValueError(f"Invalid config name: {self.config.name}")
|