Datasets:
Tags:
License:
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) |