Follow HF SQuAD dataset (#4)
Browse files* Change dataset format of the JSQuAD to follow the official HF dataset format of the SQuAD
* fix for the CI
- JGLUE.py +39 -15
- README.md +13 -26
- pyproject.toml +1 -1
- tests/JGLUE_test.py +1 -23
JGLUE.py
CHANGED
@@ -109,22 +109,18 @@ def features_jnli() -> ds.Features:
|
|
109 |
|
110 |
|
111 |
def features_jsquad() -> ds.Features:
|
112 |
-
|
113 |
-
answers = ds.Sequence(
|
114 |
-
{"text": ds.Value("string"), "answer_start": ds.Value("int64")}
|
115 |
-
)
|
116 |
-
qas = ds.Sequence(
|
117 |
{
|
118 |
-
"question": ds.Value("string"),
|
119 |
"id": ds.Value("string"),
|
120 |
-
"
|
|
|
|
|
|
|
|
|
|
|
121 |
"is_impossible": ds.Value("bool"),
|
122 |
}
|
123 |
)
|
124 |
-
paragraphs = ds.Sequence({"qas": qas, "context": ds.Value("string")})
|
125 |
-
features = ds.Features(
|
126 |
-
{"data": ds.Sequence({"title": title, "paragraphs": paragraphs})}
|
127 |
-
)
|
128 |
return features
|
129 |
|
130 |
|
@@ -515,7 +511,35 @@ class JGLUE(ds.GeneratorBasedBuilder):
|
|
515 |
if file_path is None:
|
516 |
raise ValueError(f"Invalid argument for {self.config.name}")
|
517 |
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
|
111 |
def features_jsquad() -> ds.Features:
|
112 |
+
features = ds.Features(
|
|
|
|
|
|
|
|
|
113 |
{
|
|
|
114 |
"id": ds.Value("string"),
|
115 |
+
"title": ds.Value("string"),
|
116 |
+
"context": ds.Value("string"),
|
117 |
+
"question": ds.Value("string"),
|
118 |
+
"answers": ds.Sequence(
|
119 |
+
{"text": ds.Value("string"), "answer_start": ds.Value("int32")}
|
120 |
+
),
|
121 |
"is_impossible": ds.Value("bool"),
|
122 |
}
|
123 |
)
|
|
|
|
|
|
|
|
|
124 |
return features
|
125 |
|
126 |
|
|
|
511 |
if file_path is None:
|
512 |
raise ValueError(f"Invalid argument for {self.config.name}")
|
513 |
|
514 |
+
if self.config.name == "JSQuAD":
|
515 |
+
with open(file_path, "r") as rf:
|
516 |
+
json_data = json.load(rf)
|
517 |
+
|
518 |
+
for json_dict in json_data["data"]:
|
519 |
+
title = json_dict["title"]
|
520 |
+
paragraphs = json_dict["paragraphs"]
|
521 |
+
for paragraph in paragraphs:
|
522 |
+
context = paragraph["context"]
|
523 |
+
questions = paragraph["qas"]
|
524 |
+
for question_dict in questions:
|
525 |
+
q_id = question_dict["id"]
|
526 |
+
question = question_dict["question"]
|
527 |
+
answers = question_dict["answers"]
|
528 |
+
is_impossible = question_dict["is_impossible"]
|
529 |
+
|
530 |
+
example_dict = {
|
531 |
+
"id": q_id,
|
532 |
+
"title": title,
|
533 |
+
"context": context,
|
534 |
+
"question": question,
|
535 |
+
"answers": answers,
|
536 |
+
"is_impossible": is_impossible,
|
537 |
+
}
|
538 |
+
|
539 |
+
yield q_id, example_dict
|
540 |
+
|
541 |
+
else:
|
542 |
+
with open(file_path, "r") as rf:
|
543 |
+
for i, line in enumerate(rf):
|
544 |
+
json_dict = json.loads(line)
|
545 |
+
yield i, json_dict
|
README.md
CHANGED
@@ -223,12 +223,12 @@ dataset = load_dataset("shunk031/JGLUE", name="JSQuAD")
|
|
223 |
print(dataset)
|
224 |
# DatasetDict({
|
225 |
# train: Dataset({
|
226 |
-
# features: ['
|
227 |
-
# num_rows:
|
228 |
# })
|
229 |
# validation: Dataset({
|
230 |
-
# features: ['
|
231 |
-
# num_rows:
|
232 |
# })
|
233 |
# })
|
234 |
```
|
@@ -237,28 +237,15 @@ An example of the JSQuAD looks as follows:
|
|
237 |
|
238 |
```json
|
239 |
{
|
240 |
-
"
|
241 |
-
"
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
"text": "285 km/h",
|
250 |
-
"answer_start": 182
|
251 |
-
}
|
252 |
-
],
|
253 |
-
"is_impossible": false
|
254 |
-
},
|
255 |
-
{
|
256 |
-
..
|
257 |
-
}
|
258 |
-
],
|
259 |
-
"context": "東海道新幹線 [SEP] 1987 年(昭和 62 年)4 月 1 日の国鉄分割民営化により、JR 東海が運営を継承した。西日本旅客鉄道(JR 西日本)が継承した山陽新幹線とは相互乗り入れが行われており、東海道新幹線区間のみで運転される列車にも JR 西日本所有の車両が使用されることがある。2020 年(令和 2 年)3 月現在、東京駅 - 新大阪駅間の所要時間は最速 2 時間 21 分、最高速度 285 km/h で運行されている。"
|
260 |
-
}
|
261 |
-
]
|
262 |
}
|
263 |
```
|
264 |
|
|
|
223 |
print(dataset)
|
224 |
# DatasetDict({
|
225 |
# train: Dataset({
|
226 |
+
# features: ['id', 'title', 'context', 'question', 'answers', 'is_impossible'],
|
227 |
+
# num_rows: 62859
|
228 |
# })
|
229 |
# validation: Dataset({
|
230 |
+
# features: ['id', 'title', 'context', 'question', 'answers', 'is_impossible'],
|
231 |
+
# num_rows: 4442
|
232 |
# })
|
233 |
# })
|
234 |
```
|
|
|
237 |
|
238 |
```json
|
239 |
{
|
240 |
+
"id": "a1531320p0q0",
|
241 |
+
"title": "東海道新幹線",
|
242 |
+
"context": "東海道新幹線 [SEP] 1987 年(昭和 62 年)4 月 1 日の国鉄分割民営化により、JR 東海が運営を継承した。西日本旅客鉄道(JR 西日本)が継承した山陽新幹線とは相互乗り入れが行われており、東海道新幹線区間のみで運転される列車にも JR 西日本所有の車両が使用されることがある。2020 年(令和 2 年)3 月現在、東京駅 - 新大阪駅間の所要時間は最速 2 時間 21 分、最高速度 285 km/h で運行されている。",
|
243 |
+
"question": "2020 年(令和 2 年)3 月現在、東京駅 - 新大阪駅間の最高速度はどのくらいか。",
|
244 |
+
"answers": {
|
245 |
+
"text": ["285 km/h"],
|
246 |
+
"answer_start": [182]
|
247 |
+
},
|
248 |
+
"is_impossible": false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
}
|
250 |
```
|
251 |
|
pyproject.toml
CHANGED
@@ -7,7 +7,7 @@ readme = "README.md"
|
|
7 |
packages = []
|
8 |
|
9 |
[tool.poetry.dependencies]
|
10 |
-
python = "^3.
|
11 |
datasets = "^2.10.0"
|
12 |
beautifulsoup4 = "^4.11.2"
|
13 |
mecab-python3 = "^1.0.6"
|
|
|
7 |
packages = []
|
8 |
|
9 |
[tool.poetry.dependencies]
|
10 |
+
python = "^3.8"
|
11 |
datasets = "^2.10.0"
|
12 |
beautifulsoup4 = "^4.11.2"
|
13 |
mecab-python3 = "^1.0.6"
|
tests/JGLUE_test.py
CHANGED
@@ -12,6 +12,7 @@ def dataset_path() -> str:
|
|
12 |
argvalues=(
|
13 |
("JSTS", 12451, 1457),
|
14 |
("JNLI", 20073, 2434),
|
|
|
15 |
("JCommonsenseQA", 8939, 1119),
|
16 |
),
|
17 |
)
|
@@ -27,29 +28,6 @@ def test_load_dataset(
|
|
27 |
assert dataset["validation"].num_rows == expected_num_valid
|
28 |
|
29 |
|
30 |
-
def test_load_jsquad(
|
31 |
-
dataset_path: str,
|
32 |
-
dataset_name: str = "JSQuAD",
|
33 |
-
expected_num_train: int = 62859,
|
34 |
-
expected_num_valid: int = 4442,
|
35 |
-
):
|
36 |
-
dataset = ds.load_dataset(path=dataset_path, name=dataset_name)
|
37 |
-
|
38 |
-
def count_num_data(split: str) -> int:
|
39 |
-
data = dataset[split]["data"]
|
40 |
-
assert len(data) == 1
|
41 |
-
data = data[0]
|
42 |
-
|
43 |
-
num_data = 0
|
44 |
-
for paragraphs in data["paragraphs"]:
|
45 |
-
for qas in paragraphs["qas"]:
|
46 |
-
num_data += len(qas["answers"])
|
47 |
-
return num_data
|
48 |
-
|
49 |
-
assert count_num_data("train") == expected_num_train
|
50 |
-
assert count_num_data("validation") == expected_num_valid
|
51 |
-
|
52 |
-
|
53 |
def test_load_marc_ja(
|
54 |
dataset_path: str,
|
55 |
dataset_name: str = "MARC-ja",
|
|
|
12 |
argvalues=(
|
13 |
("JSTS", 12451, 1457),
|
14 |
("JNLI", 20073, 2434),
|
15 |
+
("JSQuAD", 62859, 4442),
|
16 |
("JCommonsenseQA", 8939, 1119),
|
17 |
),
|
18 |
)
|
|
|
28 |
assert dataset["validation"].num_rows == expected_num_valid
|
29 |
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def test_load_marc_ja(
|
32 |
dataset_path: str,
|
33 |
dataset_name: str = "MARC-ja",
|