shunk031 commited on
Commit
26499b9
1 Parent(s): 843cab0

add `JGLUE.py`

Browse files
Files changed (1) hide show
  1. JGLUE.py +198 -0
JGLUE.py ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import datasets as ds
4
+
5
+ _CITATION = """\
6
+ @inproceedings{kurihara-etal-2022-jglue,
7
+ title = "{JGLUE}: {J}apanese General Language Understanding Evaluation",
8
+ author = "Kurihara, Kentaro and
9
+ Kawahara, Daisuke and
10
+ Shibata, Tomohide",
11
+ booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
12
+ month = jun,
13
+ year = "2022",
14
+ address = "Marseille, France",
15
+ publisher = "European Language Resources Association",
16
+ url = "https://aclanthology.org/2022.lrec-1.317",
17
+ pages = "2957--2966",
18
+ abstract = "To develop high-performance natural language understanding (NLU) models, it is necessary to have a benchmark to evaluate and analyze NLU ability from various perspectives. While the English NLU benchmark, GLUE, has been the forerunner, benchmarks are now being released for languages other than English, such as CLUE for Chinese and FLUE for French; but there is no such benchmark for Japanese. We build a Japanese NLU benchmark, JGLUE, from scratch without translation to measure the general NLU ability in Japanese. We hope that JGLUE will facilitate NLU research in Japanese.",
19
+ }
20
+
21
+ @InProceedings{Kurihara_nlp2022,
22
+ author = "栗原健太郎 and 河原大輔 and 柴田知秀",
23
+ title = "JGLUE: 日本語言語理解ベンチマーク",
24
+ booktitle = "言語処理学会第28回年次大会",
25
+ year = "2022",
26
+ url = "https://www.anlp.jp/proceedings/annual_meeting/2022/pdf_dir/E8-4.pdf"
27
+ note= "in Japanese"
28
+ }
29
+ """
30
+
31
+ _DESCRIPTION = """\
32
+ JGLUE, Japanese General Language Understanding Evaluation, is built to measure the general NLU ability in Japanese. JGLUE has been constructed from scratch without translation. We hope that JGLUE will facilitate NLU research in Japanese.
33
+ """
34
+
35
+ _HOMEPAGE = "https://github.com/yahoojapan/JGLUE"
36
+
37
+ _LICENSE = """\
38
+ This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
39
+ """
40
+
41
+ _DESCRIPTION_CONFIGS = {
42
+ "JSTS": "JSTS is a Japanese version of the STS (Semantic Textual Similarity) dataset. STS is a task to estimate the semantic similarity of a sentence pair.",
43
+ "JNLI": "JNLI is a Japanese version of the NLI (Natural Language Inference) dataset. NLI is a task to recognize the inference relation that a premise sentence has to a hypothesis sentence.",
44
+ "JSQuAD": "JSQuAD is a Japanese version of SQuAD (Rajpurkar+, 2016), one of the datasets of reading comprehension.",
45
+ "JCommonsenseQA": "JCommonsenseQA is a Japanese version of CommonsenseQA (Talmor+, 2019), which is a multiple-choice question answering dataset that requires commonsense reasoning ability.",
46
+ }
47
+
48
+ _URLS = {
49
+ "JSTS": {
50
+ "train": "https://raw.githubusercontent.com/yahoojapan/JGLUE/main/datasets/jsts-v1.1/train-v1.1.json",
51
+ "valid": "https://raw.githubusercontent.com/yahoojapan/JGLUE/main/datasets/jsts-v1.1/valid-v1.1.json",
52
+ },
53
+ "JNLI": {
54
+ "train": "https://raw.githubusercontent.com/yahoojapan/JGLUE/main/datasets/jnli-v1.1/train-v1.1.json",
55
+ "valid": "https://raw.githubusercontent.com/yahoojapan/JGLUE/main/datasets/jnli-v1.1/valid-v1.1.json",
56
+ },
57
+ "JSQuAD": {
58
+ "train": "https://raw.githubusercontent.com/yahoojapan/JGLUE/main/datasets/jsquad-v1.1/train-v1.1.json",
59
+ "valid": "https://raw.githubusercontent.com/yahoojapan/JGLUE/main/datasets/jsquad-v1.1/valid-v1.1.json",
60
+ },
61
+ "JCommonsenseQA": {
62
+ "train": "https://raw.githubusercontent.com/yahoojapan/JGLUE/main/datasets/jcommonsenseqa-v1.1/train-v1.1.json",
63
+ "valid": "https://raw.githubusercontent.com/yahoojapan/JGLUE/main/datasets/jcommonsenseqa-v1.1/valid-v1.1.json",
64
+ },
65
+ }
66
+
67
+
68
+ def features_jsts() -> ds.Features:
69
+ features = ds.Features(
70
+ {
71
+ "sentence_pair_id": ds.Value("string"),
72
+ "yjcaptions_id": ds.Value("string"),
73
+ "sentence1": ds.Value("string"),
74
+ "sentence2": ds.Value("string"),
75
+ "label": ds.Value("float"),
76
+ }
77
+ )
78
+ return features
79
+
80
+
81
+ def features_jnli() -> ds.Features:
82
+ features = ds.Features(
83
+ {
84
+ "sentence_pair_id": ds.Value("string"),
85
+ "yjcaptions_id": ds.Value("string"),
86
+ "sentence1": ds.Value("string"),
87
+ "sentence2": ds.Value("string"),
88
+ "label": ds.ClassLabel(
89
+ num_classes=3, names=["entailment", "contradiction", "neutral"]
90
+ ),
91
+ }
92
+ )
93
+ return features
94
+
95
+
96
+ def features_jsquad() -> ds.Features:
97
+ title = ds.Value("string")
98
+ answers = ds.Sequence(
99
+ {"text": ds.Value("string"), "answer_start": ds.Value("int64")}
100
+ )
101
+ qas = ds.Sequence(
102
+ {
103
+ "question": ds.Value("string"),
104
+ "id": ds.Value("string"),
105
+ "answers": answers,
106
+ "is_impossible": ds.Value("bool"),
107
+ }
108
+ )
109
+ paragraphs = ds.Sequence({"qas": qas, "context": ds.Value("string")})
110
+ features = ds.Features(
111
+ {"data": ds.Sequence({"title": title, "paragraphs": paragraphs})}
112
+ )
113
+ return features
114
+
115
+
116
+ def features_jcommonsenseqa() -> ds.Features:
117
+ features = ds.Features(
118
+ {
119
+ "q_id": ds.Value("int64"),
120
+ "question": ds.Value("string"),
121
+ "choice0": ds.Value("string"),
122
+ "choice1": ds.Value("string"),
123
+ "choice2": ds.Value("string"),
124
+ "choice3": ds.Value("string"),
125
+ "choice4": ds.Value("string"),
126
+ "label": ds.Value("int8"),
127
+ }
128
+ )
129
+ return features
130
+
131
+
132
+ class JGLUE(ds.GeneratorBasedBuilder):
133
+ VERSION = ds.Version("1.1.0")
134
+ BUILDER_CONFIGS = [
135
+ ds.BuilderConfig(
136
+ name="JSTS",
137
+ version=VERSION,
138
+ description=_DESCRIPTION_CONFIGS["JSTS"],
139
+ ),
140
+ ds.BuilderConfig(
141
+ name="JNLI",
142
+ version=VERSION,
143
+ description=_DESCRIPTION_CONFIGS["JNLI"],
144
+ ),
145
+ ds.BuilderConfig(
146
+ name="JSQuAD",
147
+ version=VERSION,
148
+ description=_DESCRIPTION_CONFIGS["JSQuAD"],
149
+ ),
150
+ ds.BuilderConfig(
151
+ name="JCommonsenseQA",
152
+ version=VERSION,
153
+ description=_DESCRIPTION_CONFIGS["JCommonsenseQA"],
154
+ ),
155
+ ]
156
+
157
+ def _info(self) -> ds.DatasetInfo:
158
+ if self.config.name == "JSTS":
159
+ features = features_jsts()
160
+ elif self.config.name == "JNLI":
161
+ features = features_jnli()
162
+ elif self.config.name == "JSQuAD":
163
+ features = features_jsquad()
164
+ elif self.config.name == "JCommonsenseQA":
165
+ features = features_jcommonsenseqa()
166
+ else:
167
+ raise ValueError(f"Invalid config name: {self.config.name}")
168
+
169
+ return ds.DatasetInfo(
170
+ description=_DESCRIPTION,
171
+ citation=_CITATION,
172
+ homepage=_HOMEPAGE,
173
+ license=_LICENSE,
174
+ features=features,
175
+ )
176
+
177
+ def _split_generators(self, dl_manager: ds.DownloadManager):
178
+ file_paths = dl_manager.download_and_extract(_URLS[self.config.name])
179
+ return [
180
+ ds.SplitGenerator(
181
+ name=ds.Split.TRAIN,
182
+ gen_kwargs={
183
+ "file_path": file_paths["train"],
184
+ },
185
+ ),
186
+ ds.SplitGenerator(
187
+ name=ds.Split.VALIDATION,
188
+ gen_kwargs={
189
+ "file_path": file_paths["valid"],
190
+ },
191
+ ),
192
+ ]
193
+
194
+ def _generate_examples(self, file_path: str):
195
+ with open(file_path, "r") as rf:
196
+ for i, line in enumerate(rf):
197
+ json_dict = json.loads(line)
198
+ yield i, json_dict