tabilab commited on
Commit
345eea0
1 Parent(s): 02069ea

Update links in nli_tr.py

Browse files

Dataset links were broken. Updated the dataset links with robust source aligning with the links in the dataset's repository ([ref](https://github.com/boun-tabi/NLI-TR?tab=readme-ov-file#-links)). Thanks for your time to evaluate our PR.

Files changed (1) hide show
  1. nli_tr.py +165 -165
nli_tr.py CHANGED
@@ -1,165 +1,165 @@
1
- # coding=utf-8
2
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- """NLI-TR: The Turkish translation of SNLI and MultiNLI datasets using Amazon Translate."""
16
-
17
-
18
- import json
19
- import os
20
-
21
- import datasets
22
-
23
-
24
- _CITATION = """\
25
- @inproceedings{budur-etal-2020-data,
26
- title = "Data and Representation for Turkish Natural Language Inference",
27
- author = "Budur, Emrah and
28
- \"{O}zçelik, Rıza and
29
- G\"{u}ng\"{o}r, Tunga",
30
- booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)",
31
- month = nov,
32
- year = "2020",
33
- address = "Online",
34
- publisher = "Association for Computational Linguistics",
35
- abstract = "Large annotated datasets in NLP are overwhelmingly in English. This is an obstacle to progress in other languages. Unfortunately, obtaining new annotated resources for each task in each language would be prohibitively expensive. At the same time, commercial machine translation systems are now robust. Can we leverage these systems to translate English-language datasets automatically? In this paper, we offer a positive response for natural language inference (NLI) in Turkish. We translated two large English NLI datasets into Turkish and had a team of experts validate their translation quality and fidelity to the original labels. Using these datasets, we address core issues of representation for Turkish NLI. We find that in-language embeddings are essential and that morphological parsing can be avoided where the training set is large. Finally, we show that models trained on our machine-translated datasets are successful on human-translated evaluation sets. We share all code, models, and data publicly.",
36
- }
37
- """
38
-
39
- _DESCRIPTION = """\
40
- The Natural Language Inference in Turkish (NLI-TR) is a set of two large scale datasets that were obtained by translating the foundational NLI corpora (SNLI and MNLI) using Amazon Translate.
41
- """
42
-
43
- _HOMEPAGE = "https://github.com/boun-tabi/NLI-TR"
44
-
45
-
46
- class NLITRConfig(datasets.BuilderConfig):
47
- """BuilderConfig for NLI-TR"""
48
-
49
- def __init__(self, version=None, data_url=None, **kwargs):
50
- super(NLITRConfig, self).__init__(version=datasets.Version(version, ""), **kwargs)
51
- self.data_url = data_url
52
-
53
-
54
- class NliTr(datasets.GeneratorBasedBuilder):
55
- """NLI-TR: The Turkish translation of SNLI and MultiNLI datasets using Amazon Translate."""
56
-
57
- VERSION = datasets.Version("1.0.0")
58
- BUILDER_CONFIG_CLASS = NLITRConfig
59
- BUILDER_CONFIGS = [
60
- NLITRConfig(
61
- name="snli_tr",
62
- version="1.0.0",
63
- data_url="https://tabilab.cmpe.boun.edu.tr/datasets/nli_datasets/snli_tr_1.0.zip",
64
- ),
65
- NLITRConfig(
66
- name="multinli_tr",
67
- version="1.0.0",
68
- data_url="https://tabilab.cmpe.boun.edu.tr/datasets/nli_datasets/multinli_tr_1.0.zip",
69
- ),
70
- ]
71
-
72
- def _info(self):
73
- features = datasets.Features(
74
- {
75
- "idx": datasets.Value("int32"),
76
- "premise": datasets.Value("string"),
77
- "hypothesis": datasets.Value("string"),
78
- "label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]),
79
- }
80
- )
81
- return datasets.DatasetInfo(
82
- description=_DESCRIPTION,
83
- features=datasets.Features(features),
84
- supervised_keys=None,
85
- homepage=_HOMEPAGE,
86
- citation=_CITATION,
87
- )
88
-
89
- def _split_generators(self, dl_manager):
90
- """Returns SplitGenerators."""
91
-
92
- dl_dir = dl_manager.download_and_extract(self.config.data_url)
93
- data_dir = os.path.join(dl_dir)
94
-
95
- if self.config.name == "multinli_tr":
96
- return [
97
- datasets.SplitGenerator(
98
- name=datasets.Split.TRAIN,
99
- # These kwargs will be passed to _generate_examples
100
- gen_kwargs={
101
- "filepath": os.path.join(data_dir, "multinli_tr_1.0_train.jsonl"),
102
- "split": "train",
103
- },
104
- ),
105
- datasets.SplitGenerator(
106
- name="validation_matched",
107
- # These kwargs will be passed to _generate_examples
108
- gen_kwargs={
109
- "filepath": os.path.join(data_dir, "multinli_tr_1.0_dev_matched.jsonl"),
110
- "split": "dev",
111
- },
112
- ),
113
- datasets.SplitGenerator(
114
- name="validation_mismatched",
115
- # These kwargs will be passed to _generate_examples
116
- gen_kwargs={
117
- "filepath": os.path.join(data_dir, "multinli_tr_1.0_dev_mismatched.jsonl"),
118
- "split": "dev",
119
- },
120
- ),
121
- ]
122
-
123
- if self.config.name == "snli_tr":
124
- return [
125
- datasets.SplitGenerator(
126
- name=datasets.Split.TRAIN,
127
- # These kwargs will be passed to _generate_examples
128
- gen_kwargs={
129
- "filepath": os.path.join(data_dir, "snli_tr_1.0_train.jsonl"),
130
- "split": "train",
131
- },
132
- ),
133
- datasets.SplitGenerator(
134
- name=datasets.Split.VALIDATION,
135
- # These kwargs will be passed to _generate_examples
136
- gen_kwargs={
137
- "filepath": os.path.join(data_dir, "snli_tr_1.0_dev.jsonl"),
138
- "split": "validation",
139
- },
140
- ),
141
- datasets.SplitGenerator(
142
- name=datasets.Split.TEST,
143
- # These kwargs will be passed to _generate_examples
144
- gen_kwargs={
145
- "filepath": os.path.join(data_dir, "snli_tr_1.0_test.jsonl"),
146
- "split": "test",
147
- },
148
- ),
149
- ]
150
-
151
- def _generate_examples(self, filepath, split):
152
- """Yields examples."""
153
-
154
- with open(filepath, encoding="utf-8") as f:
155
- for idx, row in enumerate(f):
156
- data = json.loads(row)
157
- example = {"idx": idx, "premise": data["sentence1"], "hypothesis": data["sentence2"]}
158
-
159
- if "gold_label" in data:
160
- if data["gold_label"] != "-":
161
- example["label"] = data["gold_label"]
162
- else:
163
- example["label"] = -1
164
-
165
- yield idx, example
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """NLI-TR: The Turkish translation of SNLI and MultiNLI datasets using Amazon Translate."""
16
+
17
+
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ _CITATION = """\
25
+ @inproceedings{budur-etal-2020-data,
26
+ title = "Data and Representation for Turkish Natural Language Inference",
27
+ author = "Budur, Emrah and
28
+ \"{O}zçelik, Rıza and
29
+ G\"{u}ng\"{o}r, Tunga",
30
+ booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)",
31
+ month = nov,
32
+ year = "2020",
33
+ address = "Online",
34
+ publisher = "Association for Computational Linguistics",
35
+ abstract = "Large annotated datasets in NLP are overwhelmingly in English. This is an obstacle to progress in other languages. Unfortunately, obtaining new annotated resources for each task in each language would be prohibitively expensive. At the same time, commercial machine translation systems are now robust. Can we leverage these systems to translate English-language datasets automatically? In this paper, we offer a positive response for natural language inference (NLI) in Turkish. We translated two large English NLI datasets into Turkish and had a team of experts validate their translation quality and fidelity to the original labels. Using these datasets, we address core issues of representation for Turkish NLI. We find that in-language embeddings are essential and that morphological parsing can be avoided where the training set is large. Finally, we show that models trained on our machine-translated datasets are successful on human-translated evaluation sets. We share all code, models, and data publicly.",
36
+ }
37
+ """
38
+
39
+ _DESCRIPTION = """\
40
+ The Natural Language Inference in Turkish (NLI-TR) is a set of two large scale datasets that were obtained by translating the foundational NLI corpora (SNLI and MNLI) using Amazon Translate.
41
+ """
42
+
43
+ _HOMEPAGE = "https://github.com/boun-tabi/NLI-TR"
44
+
45
+
46
+ class NLITRConfig(datasets.BuilderConfig):
47
+ """BuilderConfig for NLI-TR"""
48
+
49
+ def __init__(self, version=None, data_url=None, **kwargs):
50
+ super(NLITRConfig, self).__init__(version=datasets.Version(version, ""), **kwargs)
51
+ self.data_url = data_url
52
+
53
+
54
+ class NliTr(datasets.GeneratorBasedBuilder):
55
+ """NLI-TR: The Turkish translation of SNLI and MultiNLI datasets using Amazon Translate."""
56
+
57
+ VERSION = datasets.Version("1.0.0")
58
+ BUILDER_CONFIG_CLASS = NLITRConfig
59
+ BUILDER_CONFIGS = [
60
+ NLITRConfig(
61
+ name="snli_tr",
62
+ version="1.0.0",
63
+ data_url="https://nli-tr.s3.eu-central-1.amazonaws.com/snli_tr_1.0.zip",
64
+ ),
65
+ NLITRConfig(
66
+ name="multinli_tr",
67
+ version="1.0.0",
68
+ data_url="https://nli-tr.s3.eu-central-1.amazonaws.com/multinli_tr_1.0.zip",
69
+ ),
70
+ ]
71
+
72
+ def _info(self):
73
+ features = datasets.Features(
74
+ {
75
+ "idx": datasets.Value("int32"),
76
+ "premise": datasets.Value("string"),
77
+ "hypothesis": datasets.Value("string"),
78
+ "label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]),
79
+ }
80
+ )
81
+ return datasets.DatasetInfo(
82
+ description=_DESCRIPTION,
83
+ features=datasets.Features(features),
84
+ supervised_keys=None,
85
+ homepage=_HOMEPAGE,
86
+ citation=_CITATION,
87
+ )
88
+
89
+ def _split_generators(self, dl_manager):
90
+ """Returns SplitGenerators."""
91
+
92
+ dl_dir = dl_manager.download_and_extract(self.config.data_url)
93
+ data_dir = os.path.join(dl_dir)
94
+
95
+ if self.config.name == "multinli_tr":
96
+ return [
97
+ datasets.SplitGenerator(
98
+ name=datasets.Split.TRAIN,
99
+ # These kwargs will be passed to _generate_examples
100
+ gen_kwargs={
101
+ "filepath": os.path.join(data_dir, "multinli_tr_1.0_train.jsonl"),
102
+ "split": "train",
103
+ },
104
+ ),
105
+ datasets.SplitGenerator(
106
+ name="validation_matched",
107
+ # These kwargs will be passed to _generate_examples
108
+ gen_kwargs={
109
+ "filepath": os.path.join(data_dir, "multinli_tr_1.0_dev_matched.jsonl"),
110
+ "split": "dev",
111
+ },
112
+ ),
113
+ datasets.SplitGenerator(
114
+ name="validation_mismatched",
115
+ # These kwargs will be passed to _generate_examples
116
+ gen_kwargs={
117
+ "filepath": os.path.join(data_dir, "multinli_tr_1.0_dev_mismatched.jsonl"),
118
+ "split": "dev",
119
+ },
120
+ ),
121
+ ]
122
+
123
+ if self.config.name == "snli_tr":
124
+ return [
125
+ datasets.SplitGenerator(
126
+ name=datasets.Split.TRAIN,
127
+ # These kwargs will be passed to _generate_examples
128
+ gen_kwargs={
129
+ "filepath": os.path.join(data_dir, "snli_tr_1.0_train.jsonl"),
130
+ "split": "train",
131
+ },
132
+ ),
133
+ datasets.SplitGenerator(
134
+ name=datasets.Split.VALIDATION,
135
+ # These kwargs will be passed to _generate_examples
136
+ gen_kwargs={
137
+ "filepath": os.path.join(data_dir, "snli_tr_1.0_dev.jsonl"),
138
+ "split": "validation",
139
+ },
140
+ ),
141
+ datasets.SplitGenerator(
142
+ name=datasets.Split.TEST,
143
+ # These kwargs will be passed to _generate_examples
144
+ gen_kwargs={
145
+ "filepath": os.path.join(data_dir, "snli_tr_1.0_test.jsonl"),
146
+ "split": "test",
147
+ },
148
+ ),
149
+ ]
150
+
151
+ def _generate_examples(self, filepath, split):
152
+ """Yields examples."""
153
+
154
+ with open(filepath, encoding="utf-8") as f:
155
+ for idx, row in enumerate(f):
156
+ data = json.loads(row)
157
+ example = {"idx": idx, "premise": data["sentence1"], "hypothesis": data["sentence2"]}
158
+
159
+ if "gold_label" in data:
160
+ if data["gold_label"] != "-":
161
+ example["label"] = data["gold_label"]
162
+ else:
163
+ example["label"] = -1
164
+
165
+ yield idx, example