|
"""TODO(kor_nli): Add a description here.""" |
|
|
|
|
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@article{ham2020kornli, |
|
title={KorNLI and KorSTS: New Benchmark Datasets for Korean Natural Language Understanding}, |
|
author={Ham, Jiyeon and Choe, Yo Joong and Park, Kyubyong and Choi, Ilji and Soh, Hyungjoon}, |
|
journal={arXiv preprint arXiv:2004.03289}, |
|
year={2020} |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """ Korean Natural Language Inference datasets |
|
""" |
|
_URL = "https://github.com/kakaobrain/KorNLUDatasets/archive/master.zip" |
|
|
|
|
|
class KorNLIConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for KorNLI.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for KorNLI. |
|
|
|
Args: |
|
|
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
|
|
super(KorNLIConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs) |
|
|
|
|
|
class KorNli(datasets.GeneratorBasedBuilder): |
|
"""TODO(kor_nli): Short description of my dataset.""" |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
BUILDER_CONFIGS = [ |
|
KorNLIConfig(name="multi_nli", description="Korean multi NLI datasets"), |
|
KorNLIConfig(name="snli", description="Korean SNLI dataset"), |
|
KorNLIConfig(name="xnli", description="Korean XNLI dataset"), |
|
] |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
|
|
"premise": datasets.Value("string"), |
|
"hypothesis": datasets.Value("string"), |
|
"label": datasets.ClassLabel(names=["entailment", "neutral", "contradiction"]), |
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage="https://github.com/kakaobrain/KorNLUDatasets", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
dl_dir = dl_manager.download_and_extract(_URL) |
|
dl_dir = os.path.join(dl_dir, "KorNLUDatasets-master", "KorNLI") |
|
if self.config.name == "multi_nli": |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={"filepath": os.path.join(dl_dir, "multinli.train.ko.tsv")}, |
|
), |
|
] |
|
elif self.config.name == "snli": |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={"filepath": os.path.join(dl_dir, "snli_1.0_train.ko.tsv")}, |
|
), |
|
] |
|
else: |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={"filepath": os.path.join(dl_dir, "xnli.dev.ko.tsv")}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={"filepath": os.path.join(dl_dir, "xnli.test.ko.tsv")}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""Yields examples.""" |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
next(f) |
|
columns = ("premise", "hypothesis", "label") |
|
for id_, row in enumerate(f): |
|
row = row.strip().split("\t") |
|
if len(row) != 3: |
|
continue |
|
row = dict(zip(columns, row)) |
|
yield id_, row |
|
|