|
import json |
|
import csv |
|
import datasets |
|
_CITATION = """\\ |
|
@article{amirkhani2020farstail, |
|
title={FarsTail: A Persian Natural Language Inference Dataset}, |
|
author={Hossein Amirkhani, Mohammad Azari Jafari, Azadeh Amirak, Zohreh Pourjafari, Soroush Faridan Jahromi, and Zeinab Kouhkan}, |
|
journal={arXiv preprint arXiv:2009.08820}, |
|
year={2020} |
|
} |
|
""" |
|
_DESCRIPTION = """\\\\\\\\ |
|
A Persian Natural Language Inference Dataset |
|
""" |
|
|
|
_URL = "https://raw.githubusercontent.com/dml-qom/FarsTail/master/data/" |
|
_URLS = { |
|
"train": _URL + "Train-word.csv", |
|
"test": _URL + "Test-word.csv", |
|
"validation": _URL + "Val-word.csv" |
|
} |
|
class FarsTailConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for FarsTail.""" |
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for FarsTail. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(FarsTailConfig, self).__init__(**kwargs) |
|
|
|
class FarsTail(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
FarsTailConfig(name="FarsTail", version=datasets.Version("1.0.0"), description="persian NLI dataset"), |
|
] |
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
"premise": datasets.Value("string"), |
|
"hypothesis": datasets.Value("string"), |
|
"label": datasets.Value("string") |
|
} |
|
), |
|
supervised_keys=None, |
|
|
|
homepage="https://github.com/dml-qom/FarsTail", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
urls_to_download = _URLS |
|
downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["validation"]}), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
try: |
|
with open(filepath, encoding="utf-8") as f: |
|
reader = csv.DictReader(f, delimiter="\t") |
|
for idx, row in enumerate(reader): |
|
yield idx, { |
|
"premise": row["premise"], |
|
"hypothesis": row["hypothesis"], |
|
"label": row["label"], |
|
} |
|
except Exception as e: |
|
print(e) |
|
|