YNAT / YNAT.py
KimuGenie's picture
fix: bug
f336688
import datasets
import csv
_CITATION = """\
@misc{park2021klue,
title={KLUE: Korean Language Understanding Evaluation},
author={Sungjoon Park and Jihyung Moon and Sungdong Kim and Won Ik Cho and Jiyoon Han and Jangwon Park and Chisung Song and Junseong Kim and Yongsook Song and Taehwan Oh and Joohong Lee and Juhyun Oh and Sungwon Lyu and Younghoon Jeong and Inkwon Lee and Sangwoo Seo and Dongjun Lee and Hyunwoo Kim and Myeonghwa Lee and Seongbo Jang and Seungwon Do and Sunkyoung Kim and Kyungtae Lim and Jongwon Lee and Kyumin Park and Jamin Shin and Seonghyun Kim and Lucy Park and Alice Oh and Jungwoo Ha and Kyunghyun Cho},
year={2021},
eprint={2105.09680},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
"""
_LICENSE = "CC-BY-SA-4.0"
_DESCRIPTION = "klue YNAT dataset for boostcamp AI Tech data-centric project"
_DATA_URLS = {
"train": "https://huggingface.co/datasets/KimuGenie/YNAT/resolve/main/train.csv",
"test": "https://huggingface.co/datasets/KimuGenie/YNAT/resolve/main/test.csv",
}
_VERSION = "0.0.0"
class YNATConfig(datasets.BuilderConfig):
def __init__(self, data_url, **kwargs):
super().__init__(version=datasets.Version(_VERSION), **kwargs)
self.data_url = data_url
class YNAT(datasets.GeneratorBasedBuilder):
DEFAULT_CONFIG_NAME = "YNAT"
BUILDER_CONFIGS = [
YNATConfig(
name="YNAT",
data_url=_DATA_URLS,
)
]
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features(
{
"ID": datasets.Value("string")
,"input_text": datasets.Value("string")
,"label_text": datasets.Value("string")
,"target": datasets.Value("int32")
,"predefined_news_category": datasets.Value("string")
,"annotations": {
"annotators": [datasets.Value("int32")],
"annotations": {
"first-scope": [datasets.Value("string")],
"second-scope": [datasets.Value("string")],
"third-scope": [datasets.Value("string")],
}
}
,"url": datasets.Value("string")
,"date": datasets.Value("string")
}
),
description=_DESCRIPTION,
citation=_CITATION,
license=_LICENSE,
)
def _split_generators(
self,
dl_manager: datasets.DownloadManager):
data_file = dl_manager.download_and_extract(self.config.data_url)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"data_file": data_file["train"],
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"data_file": data_file["test"],
"split": "test",
},
),
]
def _generate_examples(self, data_file: str, split: str):
with open(data_file, newline='', encoding="UTF-8") as csvfile:
reader = csv.reader(csvfile, delimiter=",")
feature_names = next(reader)
idx = 0
for row in reader:
features = {
"input_text": row[1],
}
if split != "test":
features["label_text"] = row[2]
yield idx, features
idx += 1