| import os |
| import pathlib |
| from typing import overload |
| import datasets |
| import json |
|
|
| from datasets.info import DatasetInfo |
|
|
| _VERSION = "1.0.0" |
|
|
| _URL= "https://fcheck.fel.cvut.cz/downloads/NLI/snli_1.0_cs_google_translate/" |
|
|
| _URLS = { |
| "train": _URL + "snli_1.0_train.jsonl", |
| "validation": _URL + "snli_1.0_dev.jsonl", |
| "test": _URL + "snli_1.0_test.jsonl" |
| } |
|
|
| _DESCRIPTION = """\ |
| TODO: Snli_cs is a Czech translation of the Stanford NLI dataset |
| """ |
|
|
| _CITATION = """\ |
| todo |
| """ |
|
|
| _LABEL_CONVERSION = { |
| "-": "NOT ENOUGH INFO", |
| "neutral": "NOT ENOUGH INFO", |
| "entailment": "SUPPORTS", |
| "contradiction": "REFUTES" |
| } |
|
|
| datasets.utils.version.Version |
| class SnliCs(datasets.GeneratorBasedBuilder): |
| def _info(self): |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=datasets.Features( |
| { |
| "id": datasets.Value("string"), |
| "label": datasets.ClassLabel(names=["REFUTES", "NOT ENOUGH INFO", "SUPPORTS"]), |
| |
| "evidence": datasets.Value("string"), |
| "claim": datasets.Value("string"), |
| } |
| ), |
| |
| |
| supervised_keys=None, |
| version=_VERSION, |
| homepage="https://fcheck.fel.cvut.cz/dataset/", |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager: datasets.DownloadManager): |
| downloaded_files = dl_manager.download_and_extract(_URLS) |
|
|
| return [ |
| datasets.SplitGenerator(datasets.Split.TRAIN, { |
| "filepath": downloaded_files["train"] |
| }), |
| datasets.SplitGenerator(datasets.Split.VALIDATION, { |
| "filepath": downloaded_files["validation"] |
| }), |
| datasets.SplitGenerator(datasets.Split.TEST, { |
| "filepath": downloaded_files["test"] |
| }), |
| ] |
|
|
| def _generate_examples(self, filepath): |
| """This function returns the examples in the raw (text) form.""" |
| key = 0 |
| with open(filepath, encoding="utf-8") as f: |
| for line in f: |
| datapoint = json.loads(line) |
| yield key, { |
| "id": datapoint["pairID"], |
| "evidence": datapoint["sentence1"], |
| "claim": datapoint["sentence2"], |
| "label": _LABEL_CONVERSION[datapoint["gold_label"]] |
| } |
| key += 1 |
|
|