Datasets:

Modalities:
Tabular
Text
Formats:
parquet
Libraries:
Datasets
pandas
License:
File size: 4,657 Bytes
e9d5152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json
import datasets
from datasets import BuilderConfig, Features, Value, Sequence


_DESCRIPTION = """
# ν•œκ΅­μ–΄ μ§€μ‹œν•™μŠ΅ 데이터셋
- quail 데이터셋을 ν•œκ΅­μ–΄λ‘œ λ³€μ—­ν•œ 데이터셋
"""

_CITATION = """
@inproceedings{KITD,
  title={μ–Έμ–΄ λ²ˆμ—­ λͺ¨λΈμ„ ν†΅ν•œ ν•œκ΅­μ–΄ μ§€μ‹œ ν•™μŠ΅ 데이터 μ„ΈνŠΈ ꡬ좕},
  author={μž„μ˜μ„œ, μΆ”ν˜„μ°½, κΉ€μ‚°, μž₯μ§„μ˜ˆ, μ •λ―Όμ˜, μ‹ μ‚¬μž„},
  booktitle={제 35회 ν•œκΈ€ 및 ν•œκ΅­μ–΄ μ •λ³΄μ²˜λ¦¬ ν•™μˆ λŒ€νšŒ},
  pages={591--595},
  year={2023}
}
@inproceedings{KITD,
  title={Korean Instruction Tuning Dataset},
  author={Yeongseo Lim, HyeonChang Chu, San Kim, Jin Yea Jang, Minyoung Jung, Saim Shin},
  booktitle={Proceedings of the 35th Annual Conference on Human and Cognitive Language Technology},
  pages={591--595},
  year={2023}
}
"""

def _list(data_list):
    result = list()
    for data in data_list:
        result.append(data)
    return result

# quail
_QUAIL_FEATURES = Features({
    "data_index_by_user": Value(dtype="int32"),
    "id": Value(dtype="string"),
    "context_id": Value(dtype="string"),
    "question_id": Value(dtype="string"),
    "domain": Value(dtype="string"),
    "metadata": {
        "author": Value(dtype="string"),
        "title": Value(dtype="string"),
        "url": Value(dtype="string"),
    },
    "context": Value(dtype="string"),
    "question": Value(dtype="string"),
    "question_type": Value(dtype="string"),
    "answers": Sequence(Value(dtype="string")),
    "correct_answer_id": Value(dtype="int32"),
})

def _parsing_quail(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"]
        _id = data["id"]
        _context_id = data["context_id"]
        _question_id = data["question_id"]
        _domain = data["domain"]
        _metadata = {
            "author": data["metadata"]["author"],
            "title": data["metadata"]["title"],
            "url": data["metadata"]["url"]
        }
        _context = data["context"]
        _question = data["question"]
        _question_type = data["question_type"]
        _answers = _list(data["_answers"])
        _correct_answer_id = data["correct_answer_id"]
        
        yield _i, {
            "data_index_by_user": _data_index_by_user,
            "id": _id,
            "context_id": _context_id,
            "question_id": _question_id,
            "domain": _domain,
            "metadata": _metadata,
            "context": _context,
            "question": _question,
            "question_type": _question_type,
            "answers": _answers,
            "correct_answer_id": _correct_answer_id,
        }

class QuailConfig(BuilderConfig):
    def __init__(self, name, feature, reading_fn, parsing_fn, citation, **kwargs):
        super(QuailConfig, 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 QUAIL(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        QuailConfig(
            name = "base",
            data_dir = "./quail",
            feature = _QUAIL_FEATURES,
            reading_fn = _parsing_quail,
            parsing_fn = lambda x:x,
            citation = _CITATION,
        ),
    ]
    
    def _info(self) -> datasets.DatasetInfo:
        """Returns the dataset metadata."""
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=_QUAIL_FEATURES,
            citation=_CITATION,
        )
    
    def _split_generators(self, dl_manager: datasets.DownloadManager):
        """Returns SplitGenerators"""
        path_kv = {
            datasets.Split.TRAIN:[
                os.path.join(dl_manager.manual_dir, f"train.json")
            ],
            datasets.Split.VALIDATION:[
                os.path.join(dl_manager.manual_dir, f"validation.json")
            ],
            "challenge":[
                os.path.join(dl_manager.manual_dir, f"challenge.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)