Datasets:

Modalities:
Tabular
Text
Formats:
parquet
Libraries:
Datasets
pandas
License:
kor_quail / quail.py
yslim0726's picture
Upload quail.py
e9d5152
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)