import csv import os import datasets _DESCRIPTION = """\ This is the Dutch version of the original SNLI dataset. The translation was performed using Google Translate. Original SNLI available at https://nlp.stanford.edu/projects/snli/ """ class DutchSnli(datasets.GeneratorBasedBuilder): """The Dutch-translated Stanford Natural Language Inference (SNLI) Corpus.""" BUILDER_CONFIGS = [ datasets.BuilderConfig( name="plain_text", version=datasets.Version("1.0.0", ""), description="Plain text import of SNLI", ) ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "premise": datasets.Value("string"), "hypothesis": datasets.Value("string"), "label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]), } ), # No default supervised_keys (as we have to pass both premise # and hypothesis as input). supervised_keys=None, homepage="", citation="", ) def _split_generators(self, dl_manager: datasets.DownloadManager): data_dir = dl_manager._base_path return [ datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "test.tsv")} ), datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(data_dir, "train.tsv")} ), ] def _generate_examples(self, filepath): """This function returns the examples in the raw (text) form.""" with open(filepath, encoding="utf-8") as f: reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE) for idx, row in enumerate(reader): if row["label"] != '-': yield idx, { "premise": row["premise"], "hypothesis": row["hypothesis"], "label": row["label"], }