Datasets:

Modalities:
Text
Languages:
Persian
ArXiv:
Libraries:
Datasets
License:
hojjat-m commited on
Commit
578b680
1 Parent(s): 86fad7f

Create FarsTail.py

Browse files
Files changed (1) hide show
  1. FarsTail.py +76 -0
FarsTail.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import csv
3
+ import datasets
4
+ _CITATION = """\\
5
+ @article{amirkhani2020farstail,
6
+ title={FarsTail: A Persian Natural Language Inference Dataset},
7
+ author={Hossein Amirkhani, Mohammad Azari Jafari, Azadeh Amirak, Zohreh Pourjafari, Soroush Faridan Jahromi, and Zeinab Kouhkan},
8
+ journal={arXiv preprint arXiv:2009.08820},
9
+ year={2020}
10
+ }
11
+ """
12
+ _DESCRIPTION = """\\\\\\\\
13
+ A Persian Natural Language Inference Dataset
14
+ """
15
+
16
+ _URL = "https://raw.githubusercontent.com/dml-qom/FarsTail/master/data/"
17
+ _URLS = {
18
+ "train": _URL + "Train-word.csv",
19
+ "test": _URL + "Test-word.csv",
20
+ "validation": _URL + "Val-word.csv"
21
+ }
22
+ class FarsTailConfig(datasets.BuilderConfig):
23
+ """BuilderConfig for FarsTail."""
24
+ def __init__(self, **kwargs):
25
+ """BuilderConfig for FarsTail.
26
+ Args:
27
+ **kwargs: keyword arguments forwarded to super.
28
+ """
29
+ super(FarsTailConfig, self).__init__(**kwargs)
30
+
31
+ class FarsTail(datasets.GeneratorBasedBuilder):
32
+ BUILDER_CONFIGS = [
33
+ FarsTailConfig(name="FarsTail", version=datasets.Version("1.0.0"), description="persian NLI dataset"),
34
+ ]
35
+ def _info(self):
36
+ return datasets.DatasetInfo(
37
+ # This is the description that will appear on the datasets page.
38
+ description=_DESCRIPTION,
39
+ # datasets.features.FeatureConnectors
40
+ features=datasets.Features(
41
+ {
42
+ "premise": datasets.Value("string"),
43
+ "hypothesis": datasets.Value("string"),
44
+ "label": datasets.Value("string")
45
+ }
46
+ ),
47
+ supervised_keys=None,
48
+ # Homepage of the dataset for documentation
49
+ homepage="https://github.com/dml-qom/FarsTail",
50
+ citation=_CITATION,
51
+ )
52
+
53
+ def _split_generators(self, dl_manager):
54
+ """Returns SplitGenerators."""
55
+ # dl_manager is a datasets.download.DownloadManager that can be used to
56
+ # download and extract URLs
57
+ urls_to_download = _URLS
58
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
59
+ return [
60
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
61
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
62
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["validation"]}),
63
+ ]
64
+
65
+ def _generate_examples(self, filepath):
66
+ try:
67
+ with open(filepath, encoding="utf-8") as f:
68
+ reader = csv.DictReader(f, delimiter="\t")
69
+ for idx, row in enumerate(reader):
70
+ yield idx, {
71
+ "premise": row["premise"],
72
+ "hypothesis": row["hypothesis"],
73
+ "label": row["label"],
74
+ }
75
+ except Exception as e:
76
+ print(e)