Datasets:
Upload JAQKET.py
Browse files
JAQKET.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import random
|
3 |
+
import string
|
4 |
+
import warnings
|
5 |
+
from typing import Dict, List, Optional, Union
|
6 |
+
|
7 |
+
import datasets as ds
|
8 |
+
import pandas as pd
|
9 |
+
|
10 |
+
_CITATION = """
|
11 |
+
@InProceedings{Kurihara_nlp2020,
|
12 |
+
author = "鈴木正敏 and 鈴木潤 and 松田耕史 and ⻄田京介 and 井之上直也",
|
13 |
+
title = "JAQKET: クイズを題材にした日本語 QA データセットの構築",
|
14 |
+
booktitle = "言語処理学会第26回年次大会",
|
15 |
+
year = "2020",
|
16 |
+
url = "https://www.anlp.jp/proceedings/annual_meeting/2020/pdf_dir/P2-24.pdf"
|
17 |
+
note= "in Japanese"
|
18 |
+
"""
|
19 |
+
|
20 |
+
_DESCRIPTION = """\
|
21 |
+
JAQKET: JApanese Questions on Knowledge of EnTitie
|
22 |
+
"""
|
23 |
+
|
24 |
+
_HOMEPAGE = "https://sites.google.com/view/project-aio/dataset"
|
25 |
+
|
26 |
+
_LICENSE = """\
|
27 |
+
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
|
28 |
+
"""
|
29 |
+
|
30 |
+
_DESCRIPTION_CONFIGS = {
|
31 |
+
"v2.0": "v2.0",
|
32 |
+
}
|
33 |
+
|
34 |
+
_URLS = {
|
35 |
+
"v2.0": {
|
36 |
+
"train": "https://huggingface.co/datasets/kumapo/JAQKET/resolve/main/train_jaqket_59.350.json",
|
37 |
+
"dev": "https://huggingface.co/datasets/kumapo/JAQKET/resolve/main/dev_jaqket_59.350.json",
|
38 |
+
},
|
39 |
+
}
|
40 |
+
|
41 |
+
def dataset_info_v2() -> ds.Features:
|
42 |
+
features = ds.Features(
|
43 |
+
{
|
44 |
+
"qid": ds.Value("string"),
|
45 |
+
"question": ds.Value("string"),
|
46 |
+
"answers": ds.Sequence({
|
47 |
+
"text": ds.Value("string")
|
48 |
+
}),
|
49 |
+
"ctxs": ds.Sequence({
|
50 |
+
"id": ds.Value("string"),
|
51 |
+
"title": ds.Value("string"),
|
52 |
+
"text": ds.Value("string"),
|
53 |
+
"score": ds.Value("float32"),
|
54 |
+
"has_answer": ds.Value("bool"),
|
55 |
+
})
|
56 |
+
}
|
57 |
+
)
|
58 |
+
return ds.DatasetInfo(
|
59 |
+
description=_DESCRIPTION,
|
60 |
+
citation=_CITATION,
|
61 |
+
homepage=_HOMEPAGE,
|
62 |
+
license=_LICENSE,
|
63 |
+
features=features,
|
64 |
+
)
|
65 |
+
|
66 |
+
|
67 |
+
class JAQKET(ds.GeneratorBasedBuilder):
|
68 |
+
VERSION = ds.Version("0.1.0")
|
69 |
+
BUILDER_CONFIGS = [
|
70 |
+
ds.BuilderConfig(
|
71 |
+
name="v2.0",
|
72 |
+
version=VERSION,
|
73 |
+
description=_DESCRIPTION_CONFIGS["v2.0"],
|
74 |
+
),
|
75 |
+
]
|
76 |
+
|
77 |
+
def _info(self) -> ds.DatasetInfo:
|
78 |
+
if self.config.name == "v2.0":
|
79 |
+
return dataset_info_v2()
|
80 |
+
else:
|
81 |
+
raise ValueError(f"Invalid config name: {self.config.name}")
|
82 |
+
|
83 |
+
def _split_generators(self, dl_manager: ds.DownloadManager):
|
84 |
+
file_paths = dl_manager.download_and_extract(_URLS[self.config.name])
|
85 |
+
return [
|
86 |
+
ds.SplitGenerator(
|
87 |
+
name=ds.Split.TRAIN,
|
88 |
+
gen_kwargs={"file_path": file_paths["train"]},
|
89 |
+
),
|
90 |
+
ds.SplitGenerator(
|
91 |
+
name=ds.Split.VALIDATION,
|
92 |
+
gen_kwargs={"file_path": file_paths["valid"]},
|
93 |
+
),
|
94 |
+
]
|
95 |
+
|
96 |
+
def _generate_examples(
|
97 |
+
self,
|
98 |
+
file_path: Optional[str] = None,
|
99 |
+
split_df: Optional[pd.DataFrame] = None,
|
100 |
+
):
|
101 |
+
if file_path is None:
|
102 |
+
raise ValueError(f"Invalid argument for {self.config.name}")
|
103 |
+
|
104 |
+
with open(file_path, "r") as rf:
|
105 |
+
json_data = json.load(rf)
|
106 |
+
|
107 |
+
for json_dict in json_data:
|
108 |
+
q_id = json_dict["qid"]
|
109 |
+
question = json_dict["question"]
|
110 |
+
answers = [{"text": answer} for answer in json_dict["answers"]]
|
111 |
+
ctxs = [
|
112 |
+
{
|
113 |
+
"id": ctx["id"],
|
114 |
+
"title": ctx["title"],
|
115 |
+
"text": ctx["text"],
|
116 |
+
"score": float(ctx["score"]),
|
117 |
+
"has_answer": ctx["has_answer"]
|
118 |
+
|
119 |
+
}
|
120 |
+
for ctx in json_dict["ctxs"]
|
121 |
+
]
|
122 |
+
example_dict = {
|
123 |
+
"qid": q_id,
|
124 |
+
"question": question,
|
125 |
+
"answers": answers,
|
126 |
+
"ctxs": ctxs
|
127 |
+
}
|
128 |
+
yield q_id, example_dict
|