File size: 1,815 Bytes
3b0ffb0 |
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 |
from __future__ import absolute_import, division, print_function
import datasets
_URL = "data/"
_URLs = {
"train": _URL + "train.tsv",
"valid": _URL + "valid.tsv",
"test": _URL + "test.tsv",
}
class KlueTC(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description="KLUE Topic Classification (Dev Split)",
features=datasets.Features(
{
"text": datasets.Value("string"),
"label": datasets.features.ClassLabel(names=['정치', '세계', 'IT과학', '스포츠', '사회', '경제', '생활문화']),
}
),
supervised_keys=None,
license="",
homepage="",
citation="",
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download_and_extract(_URLs)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": downloaded_files["train"],
}
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepath": downloaded_files["valid"],
}
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": downloaded_files["test"],
}
),
]
def _generate_examples(self, filepath):
with open(filepath, "r", encoding='UTF-8') as f:
for idx, line in enumerate(f):
text, label = line.split("\t")
yield idx, {"text": text.strip(), "label": label.strip()}
|