|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""CsFEVERv2 dataset""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
This new dataset is aimed on Czech fact-checking task. |
|
""" |
|
|
|
_CITATION = "" |
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
_URLS = { |
|
"original": {"train": "./original/train.jsonl", |
|
"dev" : "./original/dev.jsonl", |
|
"test": "./original/test.jsonl"}, |
|
"f1": {"train": "./f1/train.jsonl", |
|
"dev" : "./f1/dev.jsonl", |
|
"test": "./f1/test.jsonl"}, |
|
"precision": {"train": "./precision/train.jsonl", |
|
"dev" : "./precision/dev.jsonl", |
|
"test": "./precision/test.jsonl"}, |
|
"07": {"train": "./07/train.jsonl", |
|
"dev" : "./07/dev.jsonl", |
|
"test": "./07/test.jsonl"}, |
|
"wiki_pages": "./wiki_pages/wiki_pages.jsonl", |
|
"original_nli": {"train": "./original_nli/train.jsonl", |
|
"dev" : "./original_nli/dev.jsonl", |
|
"test": "./original_nli/test.jsonl"}, |
|
"f1_nli": {"train": "./f1_nli/train.jsonl", |
|
"dev" : "./f1_nli/dev.jsonl", |
|
"test": "./f1_nli/test.jsonl"}, |
|
"07_nli": {"train": "./07_nli/train.jsonl", |
|
"dev" : "./07_nli/dev.jsonl", |
|
"test": "./07_nli/test.jsonl"}, |
|
"precision_nli": {"train": "./precision_nli/train.jsonl", |
|
"dev" : "./precision_nli/dev.jsonl", |
|
"test": "./precision_nli/test.jsonl"}, |
|
} |
|
|
|
_ORIGINAL_DESCRIPTION = "" |
|
|
|
_NLI_NAMES = ["original_nli", "07_nli", "precision_nli", "f1_nli"] |
|
|
|
|
|
|
|
class CsFEVERv2(datasets.GeneratorBasedBuilder): |
|
"""CsFEVERv2""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="original", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION, |
|
), |
|
datasets.BuilderConfig( |
|
name="f1", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION, |
|
), |
|
datasets.BuilderConfig( |
|
name="precision", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION |
|
), |
|
datasets.BuilderConfig( |
|
name="07", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION |
|
), |
|
datasets.BuilderConfig( |
|
name="wiki_pages", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION |
|
), |
|
datasets.BuilderConfig( |
|
name="original_nli", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION |
|
), |
|
datasets.BuilderConfig( |
|
name="07_nli", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION |
|
), |
|
datasets.BuilderConfig( |
|
name="f1_nli", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION |
|
), |
|
datasets.BuilderConfig( |
|
name="precision_nli", |
|
version=VERSION, |
|
description=_ORIGINAL_DESCRIPTION |
|
), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "original" |
|
|
|
def _info(self): |
|
|
|
if self.config.name == "original": |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int32"), |
|
"label": datasets.Value("string"), |
|
"predicted_label": datasets.Value("string"), |
|
"predicted_score": datasets.Value("float"), |
|
"claim": datasets.Value("string"), |
|
"evidence": datasets.Sequence(datasets.Sequence(datasets.Value("string"))), |
|
|
|
} |
|
) |
|
elif self.config.name in _NLI_NAMES: |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int32"), |
|
"label": datasets.ClassLabel(num_classes=3, names=["SUPPORTS", "REFUTES", "NOT ENOUGH INFO"]), |
|
"claim": datasets.Value("string"), |
|
"evidence": datasets.Value("string"), |
|
|
|
} |
|
) |
|
elif self.config.name == "wiki_pages": |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int32"), |
|
"revid": datasets.Value("int32"), |
|
"url": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
|
|
} |
|
) |
|
else: |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int32"), |
|
"label": datasets.Value("string"), |
|
"claim": datasets.Value("string"), |
|
"evidence": datasets.Sequence(datasets.Sequence(datasets.Value("string"))), |
|
|
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
|
|
urls = _URLS[self.config.name] |
|
data_dir = dl_manager.download_and_extract(urls) |
|
if self.config.name == "wiki_pages": |
|
return [datasets.SplitGenerator( |
|
name="wiki_pages", |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir, |
|
"split": "wiki_pages", |
|
}, |
|
)] |
|
else: |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir["train"], |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir["dev"], |
|
"split": "dev", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir["test"], |
|
"split": "test" |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
|
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
for key, row in enumerate(f): |
|
data_point = json.loads(row) |
|
if self.config.name == "original": |
|
|
|
yield key, { |
|
"id": data_point["id"], |
|
"label": data_point["label"], |
|
"predicted_label": data_point["predicted_label"], |
|
"predicted_score": data_point["predicted_score"], |
|
"claim": data_point["claim"], |
|
"evidence": data_point["evidence"], |
|
} |
|
elif self.config.name in _NLI_NAMES: |
|
yield key, { |
|
"id": data_point["id"], |
|
"label": data_point["label"], |
|
"claim": data_point["claim"], |
|
"evidence": data_point["evidence"], |
|
} |
|
elif self.config.name == "wiki_pages": |
|
yield key, { |
|
"id": data_point["id"], |
|
"revid": data_point["revid"], |
|
"url": data_point["url"], |
|
"title": data_point["title"], |
|
"text": data_point["text"], |
|
} |
|
else: |
|
yield key, { |
|
"id": data_point["id"], |
|
"label": data_point["label"], |
|
"claim": data_point["claim"], |
|
"evidence": data_point["evidence"], |
|
} |