Commit
·
7fd7df1
1
Parent(s):
04e363c
Add data loader
Browse files- dutch-snli.py +62 -0
dutch-snli.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import os
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
_DESCRIPTION = """\
|
9 |
+
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/
|
10 |
+
"""
|
11 |
+
|
12 |
+
|
13 |
+
class DutchSnli(datasets.GeneratorBasedBuilder):
|
14 |
+
"""The Dutch-translated Stanford Natural Language Inference (SNLI) Corpus."""
|
15 |
+
|
16 |
+
BUILDER_CONFIGS = [
|
17 |
+
datasets.BuilderConfig(
|
18 |
+
name="plain_text",
|
19 |
+
version=datasets.Version("1.0.0", ""),
|
20 |
+
description="Plain text import of SNLI",
|
21 |
+
)
|
22 |
+
]
|
23 |
+
|
24 |
+
def _info(self):
|
25 |
+
return datasets.DatasetInfo(
|
26 |
+
description=_DESCRIPTION,
|
27 |
+
features=datasets.Features(
|
28 |
+
{
|
29 |
+
"premise": datasets.Value("string"),
|
30 |
+
"hypothesis": datasets.Value("string"),
|
31 |
+
"label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]),
|
32 |
+
}
|
33 |
+
),
|
34 |
+
# No default supervised_keys (as we have to pass both premise
|
35 |
+
# and hypothesis as input).
|
36 |
+
supervised_keys=None,
|
37 |
+
homepage="",
|
38 |
+
citation="",
|
39 |
+
)
|
40 |
+
|
41 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
42 |
+
data_dir = dl_manager._base_path
|
43 |
+
return [
|
44 |
+
datasets.SplitGenerator(
|
45 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "test.tsv")}
|
46 |
+
),
|
47 |
+
datasets.SplitGenerator(
|
48 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(data_dir, "train.tsv")}
|
49 |
+
),
|
50 |
+
]
|
51 |
+
|
52 |
+
def _generate_examples(self, filepath):
|
53 |
+
"""This function returns the examples in the raw (text) form."""
|
54 |
+
with open(filepath, encoding="utf-8") as f:
|
55 |
+
reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
56 |
+
for idx, row in enumerate(reader):
|
57 |
+
if row["label"] != '-':
|
58 |
+
yield idx, {
|
59 |
+
"premise": row["premise"],
|
60 |
+
"hypothesis": row["hypothesis"],
|
61 |
+
"label": row["label"],
|
62 |
+
}
|