Datasets:

Modalities:
Tabular
Text
Formats:
parquet
Libraries:
Datasets
pandas
License:
File size: 7,374 Bytes
2a235ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import os
import json
import datasets
from datasets import BuilderConfig, Features, ClassLabel, Value, Sequence


_DESCRIPTION = """
# ํ•œ๊ตญ์–ด ์ง€์‹œํ•™์Šต ๋ฐ์ดํ„ฐ์…‹
- glue ๋ฐ์ดํ„ฐ์…‹์„ ํ•œ๊ตญ์–ด๋กœ ๋ณ€์—ญํ•œ ๋ฐ์ดํ„ฐ์…‹
"""

_CITATION = """
@inproceedings{KITD,
  title={์–ธ์–ด ๋ฒˆ์—ญ ๋ชจ๋ธ์„ ํ†ตํ•œ ํ•œ๊ตญ์–ด ์ง€์‹œ ํ•™์Šต ๋ฐ์ดํ„ฐ ์„ธํŠธ ๊ตฌ์ถ•},
  author={์ž„์˜์„œ, ์ถ”ํ˜„์ฐฝ, ๊น€์‚ฐ, ์žฅ์ง„์˜ˆ, ์ •๋ฏผ์˜, ์‹ ์‚ฌ์ž„},
  booktitle={์ œ 35ํšŒ ํ•œ๊ธ€ ๋ฐ ํ•œ๊ตญ์–ด ์ •๋ณด์ฒ˜๋ฆฌ ํ•™์ˆ ๋Œ€ํšŒ},
  pages={591--595},
  month=oct,
  year={2023}
}
"""

# glue
_COLA_FEATURES = Features({
    "data_index_by_user": Value(dtype="int32"),
    "label": Value(dtype="int32"),
    "sentence": Value(dtype="string"),    
})

def _parsing_cola(file_path):
    with open(file_path, mode="r") as f:
        dataset = json.load(f)
    for _idx, data in enumerate(dataset):
        _data_index_by_user = data["data_index_by_user"]
        _label = data["label"]
        _sentence = data["sentence"]

        yield _idx, {
            "data_index_by_user": _data_index_by_user,
            "label": _label,
            "sentence": _sentence
        }

_MRPC_FEATURES = Features({
    "data_index_by_user": Value(dtype="int32"),
    "sentence1": Value(dtype="string"),
    "sentence2": Value(dtype="string"),
    "label": Value(dtype="int32"),
    "idx": Value(dtype="int32")
})

def _parsing_mrpc(file_path):
    with open(file_path, mode="r") as f:
        dataset = json.load(f)
    for _i, data in enumerate(dataset):
        _data_index_by_user = data["data_index_by_user"]
        _sentence1 = data["sentence1"]
        _sentence2 = data["sentence2"]
        _label = data["label"]
        _idx = data["idx"]

        yield _i, {
            "data_index_by_user": _data_index_by_user,
            "sentence1": _sentence1,
            "sentence2": _sentence2,
            "label": _label,
            "idx": _idx,
        }

_QNLI_FEATURES = Features({
    "data_index_by_user": Value(dtype="int32"),
    "label": Value(dtype="int32"),
    "question": Value(dtype="string"),
    "sentence": Value(dtype="string"),
})

def _parsing_qnli(file_path):
    with open(file_path, mode="r") as f:
        dataset = json.load(f)
    for _idx, data in enumerate(dataset):
        _data_index_by_user = data["data_index_by_user"]
        _label = data["label"]
        _question = data["question"]
        _sentence = data["sentence"]

        yield _idx, {
            "data_index_by_user": _data_index_by_user,
            "label": _label,
            "question": _question,
            "sentence": _sentence,
        }

_QQP_FEATURES = Features({
    "data_index_by_user": Value(dtype="int32"),
    "question1": Value(dtype="string"),
    "question2": Value(dtype="string"),
    "label": Value(dtype="int32"),
    "idx": Value(dtype="int32")
})

def _parsing_qqp(file_path):
    with open(file_path, mode="r") as f:
        dataset = json.load(f)
    for _i, data in enumerate(dataset):
        _data_index_by_user = data["data_index_by_user"]
        _question1 = data["question1"]
        _question2 = data["question2"]
        _label = data["label"]
        _idx = data["idx"]

        yield _i, {
            "data_index_by_user": _data_index_by_user,
            "question1": _question1,
            "question2": _question2,
            "label": _label,
            "idx": _idx,
        }

_WNLI_FEATURES = Features({
    "data_index_by_user": Value(dtype="int32"),
    "sentence1": Value(dtype="string"),
    "sentence2": Value(dtype="string"),
    "label": Value(dtype="int32"),
    "idx": Value(dtype="int32")
})

def _parsing_wnli(file_path):
    with open(file_path, mode="r") as f:
        dataset = json.load(f)
    for _i, data in enumerate(dataset):
        _data_index_by_user = data["data_index_by_user"]
        _sentence1 = data["sentence1"]
        _sentence2 = data["sentence2"]
        _label = data["label"]
        _idx = data["idx"]

        yield _i, {
            "data_index_by_user": _data_index_by_user,
            "sentence1": _sentence1,
            "sentence2": _sentence2,
            "label": _label,
            "idx": _idx,
        }

class GlueConfig(BuilderConfig):
    def __init__(self, name, feature, reading_fn, parsing_fn, citation, **kwargs):
        super(GlueConfig, self).__init__(
            name = name,
            version=datasets.Version("1.0.0"),
            **kwargs)
        self.feature = feature
        self.reading_fn = reading_fn
        self.parsing_fn = parsing_fn
        self.citation = citation

class GLUE(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        GlueConfig(
            name = "cola",
            data_dir = "./glue",
            feature = _COLA_FEATURES,
            reading_fn = _parsing_cola,
            parsing_fn = lambda x:x,
            citation = _CITATION,
        ),
        GlueConfig(
            name = "mrpc",
            data_dir = "./glue",
            feature = _MRPC_FEATURES,
            reading_fn = _parsing_mrpc,
            parsing_fn = lambda x:x,
            citation = _CITATION,
        ),
        GlueConfig(
            name = "qnli",
            data_dir = "./glue",
            feature = _QNLI_FEATURES,
            reading_fn = _parsing_qnli,
            parsing_fn = lambda x:x,
            citation = _CITATION,
        ),
        GlueConfig(
            name = "qqp",
            data_dir = "./glue",
            feature = _QQP_FEATURES,
            reading_fn = _parsing_qqp,
            parsing_fn = lambda x:x,
            citation = _CITATION,
        ),
        GlueConfig(
            name = "wnli",
            data_dir = "./glue",
            feature = _WNLI_FEATURES,
            reading_fn = _parsing_wnli,
            parsing_fn = lambda x:x,
            citation = _CITATION,
        ),
    ]
    
    def _info(self) -> datasets.DatasetInfo:
        """Returns the dataset metadata."""
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=self.config.feature,
            citation=_CITATION,
        )
    
    def _split_generators(self, dl_manager: datasets.DownloadManager):
        """Returns SplitGenerators"""
        if self.config.name == "qqp":
            path_kv = {
                datasets.Split.TRAIN:[
                    os.path.join(dl_manager.manual_dir, f"{self.config.name}/train.json")
                ],
            }
        else:
            path_kv = {
                datasets.Split.TRAIN:[
                    os.path.join(dl_manager.manual_dir, f"{self.config.name}/train.json")
                ],
                datasets.Split.VALIDATION:[
                    os.path.join(dl_manager.manual_dir, f"{self.config.name}/validation.json")
                ],
                datasets.Split.TEST:[
                    os.path.join(dl_manager.manual_dir, f"{self.config.name}/test.json")
                ],
            }
        return [
            datasets.SplitGenerator(name=k, gen_kwargs={"path_list": v})
            for k, v in path_kv.items()
        ]
    
    def _generate_examples(self, path_list):
        """Yields examples."""
        for path in path_list:
            try:
                for example in iter(self.config.reading_fn(path)):
                    yield self.config.parsing_fn(example)
            except Exception as e:
                print(e)