Quentin Lhoest commited on
Commit
6d30e6e
1 Parent(s): 953755b

Release: 1.18.1

Browse files

Commit from https://github.com/huggingface/datasets/commit/218e496519ff14b4bc69ea559616af6f2ef89e57

Files changed (1) hide show
  1. nli_tr.py +166 -166
nli_tr.py CHANGED
@@ -1,166 +1,166 @@
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 codecs
19
- import json
20
- import os
21
-
22
- import datasets
23
-
24
-
25
- _CITATION = """\
26
- @inproceedings{budur-etal-2020-data,
27
- title = "Data and Representation for Turkish Natural Language Inference",
28
- author = "Budur, Emrah and
29
- \"{O}zçelik, Rıza and
30
- G\"{u}ng\"{o}r, Tunga",
31
- booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)",
32
- month = nov,
33
- year = "2020",
34
- address = "Online",
35
- publisher = "Association for Computational Linguistics",
36
- 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.",
37
- }
38
- """
39
-
40
- _DESCRIPTION = """\
41
- 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.
42
- """
43
-
44
- _HOMEPAGE = "https://github.com/boun-tabi/NLI-TR"
45
-
46
-
47
- class NLITRConfig(datasets.BuilderConfig):
48
- """BuilderConfig for NLI-TR"""
49
-
50
- def __init__(self, version=None, data_url=None, **kwargs):
51
- super(NLITRConfig, self).__init__(version=datasets.Version(version, ""), **kwargs)
52
- self.data_url = data_url
53
-
54
-
55
- class NliTr(datasets.GeneratorBasedBuilder):
56
- """NLI-TR: The Turkish translation of SNLI and MultiNLI datasets using Amazon Translate."""
57
-
58
- VERSION = datasets.Version("1.0.0")
59
- BUILDER_CONFIG_CLASS = NLITRConfig
60
- BUILDER_CONFIGS = [
61
- NLITRConfig(
62
- name="snli_tr",
63
- version="1.0.0",
64
- data_url="https://tabilab.cmpe.boun.edu.tr/datasets/nli_datasets/snli_tr_1.0.zip",
65
- ),
66
- NLITRConfig(
67
- name="multinli_tr",
68
- version="1.0.0",
69
- data_url="https://tabilab.cmpe.boun.edu.tr/datasets/nli_datasets/multinli_tr_1.0.zip",
70
- ),
71
- ]
72
-
73
- def _info(self):
74
- features = datasets.Features(
75
- {
76
- "idx": datasets.Value("int32"),
77
- "premise": datasets.Value("string"),
78
- "hypothesis": datasets.Value("string"),
79
- "label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]),
80
- }
81
- )
82
- return datasets.DatasetInfo(
83
- description=_DESCRIPTION,
84
- features=datasets.Features(features),
85
- supervised_keys=None,
86
- homepage=_HOMEPAGE,
87
- citation=_CITATION,
88
- )
89
-
90
- def _split_generators(self, dl_manager):
91
- """Returns SplitGenerators."""
92
-
93
- dl_dir = dl_manager.download_and_extract(self.config.data_url)
94
- data_dir = os.path.join(dl_dir)
95
-
96
- if self.config.name == "multinli_tr":
97
- return [
98
- datasets.SplitGenerator(
99
- name=datasets.Split.TRAIN,
100
- # These kwargs will be passed to _generate_examples
101
- gen_kwargs={
102
- "filepath": os.path.join(data_dir, "multinli_tr_1.0_train.jsonl"),
103
- "split": "train",
104
- },
105
- ),
106
- datasets.SplitGenerator(
107
- name="validation_matched",
108
- # These kwargs will be passed to _generate_examples
109
- gen_kwargs={
110
- "filepath": os.path.join(data_dir, "multinli_tr_1.0_dev_matched.jsonl"),
111
- "split": "dev",
112
- },
113
- ),
114
- datasets.SplitGenerator(
115
- name="validation_mismatched",
116
- # These kwargs will be passed to _generate_examples
117
- gen_kwargs={
118
- "filepath": os.path.join(data_dir, "multinli_tr_1.0_dev_mismatched.jsonl"),
119
- "split": "dev",
120
- },
121
- ),
122
- ]
123
-
124
- if self.config.name == "snli_tr":
125
- return [
126
- datasets.SplitGenerator(
127
- name=datasets.Split.TRAIN,
128
- # These kwargs will be passed to _generate_examples
129
- gen_kwargs={
130
- "filepath": os.path.join(data_dir, "snli_tr_1.0_train.jsonl"),
131
- "split": "train",
132
- },
133
- ),
134
- datasets.SplitGenerator(
135
- name=datasets.Split.VALIDATION,
136
- # These kwargs will be passed to _generate_examples
137
- gen_kwargs={
138
- "filepath": os.path.join(data_dir, "snli_tr_1.0_dev.jsonl"),
139
- "split": "validation",
140
- },
141
- ),
142
- datasets.SplitGenerator(
143
- name=datasets.Split.TEST,
144
- # These kwargs will be passed to _generate_examples
145
- gen_kwargs={
146
- "filepath": os.path.join(data_dir, "snli_tr_1.0_test.jsonl"),
147
- "split": "test",
148
- },
149
- ),
150
- ]
151
-
152
- def _generate_examples(self, filepath, split):
153
- """Yields examples."""
154
-
155
- with codecs.open(filepath, encoding="utf-8") as f:
156
- for idx, row in enumerate(f):
157
- data = json.loads(row)
158
- example = {"idx": idx, "premise": data["sentence1"], "hypothesis": data["sentence2"]}
159
-
160
- if "gold_label" in data:
161
- if data["gold_label"] != "-":
162
- example["label"] = data["gold_label"]
163
- else:
164
- example["label"] = -1
165
-
166
- 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 codecs
19
+ import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ _CITATION = """\
26
+ @inproceedings{budur-etal-2020-data,
27
+ title = "Data and Representation for Turkish Natural Language Inference",
28
+ author = "Budur, Emrah and
29
+ \"{O}zçelik, Rıza and
30
+ G\"{u}ng\"{o}r, Tunga",
31
+ booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)",
32
+ month = nov,
33
+ year = "2020",
34
+ address = "Online",
35
+ publisher = "Association for Computational Linguistics",
36
+ 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.",
37
+ }
38
+ """
39
+
40
+ _DESCRIPTION = """\
41
+ 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.
42
+ """
43
+
44
+ _HOMEPAGE = "https://github.com/boun-tabi/NLI-TR"
45
+
46
+
47
+ class NLITRConfig(datasets.BuilderConfig):
48
+ """BuilderConfig for NLI-TR"""
49
+
50
+ def __init__(self, version=None, data_url=None, **kwargs):
51
+ super(NLITRConfig, self).__init__(version=datasets.Version(version, ""), **kwargs)
52
+ self.data_url = data_url
53
+
54
+
55
+ class NliTr(datasets.GeneratorBasedBuilder):
56
+ """NLI-TR: The Turkish translation of SNLI and MultiNLI datasets using Amazon Translate."""
57
+
58
+ VERSION = datasets.Version("1.0.0")
59
+ BUILDER_CONFIG_CLASS = NLITRConfig
60
+ BUILDER_CONFIGS = [
61
+ NLITRConfig(
62
+ name="snli_tr",
63
+ version="1.0.0",
64
+ data_url="https://tabilab.cmpe.boun.edu.tr/datasets/nli_datasets/snli_tr_1.0.zip",
65
+ ),
66
+ NLITRConfig(
67
+ name="multinli_tr",
68
+ version="1.0.0",
69
+ data_url="https://tabilab.cmpe.boun.edu.tr/datasets/nli_datasets/multinli_tr_1.0.zip",
70
+ ),
71
+ ]
72
+
73
+ def _info(self):
74
+ features = datasets.Features(
75
+ {
76
+ "idx": datasets.Value("int32"),
77
+ "premise": datasets.Value("string"),
78
+ "hypothesis": datasets.Value("string"),
79
+ "label": datasets.features.ClassLabel(names=["entailment", "neutral", "contradiction"]),
80
+ }
81
+ )
82
+ return datasets.DatasetInfo(
83
+ description=_DESCRIPTION,
84
+ features=datasets.Features(features),
85
+ supervised_keys=None,
86
+ homepage=_HOMEPAGE,
87
+ citation=_CITATION,
88
+ )
89
+
90
+ def _split_generators(self, dl_manager):
91
+ """Returns SplitGenerators."""
92
+
93
+ dl_dir = dl_manager.download_and_extract(self.config.data_url)
94
+ data_dir = os.path.join(dl_dir)
95
+
96
+ if self.config.name == "multinli_tr":
97
+ return [
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TRAIN,
100
+ # These kwargs will be passed to _generate_examples
101
+ gen_kwargs={
102
+ "filepath": os.path.join(data_dir, "multinli_tr_1.0_train.jsonl"),
103
+ "split": "train",
104
+ },
105
+ ),
106
+ datasets.SplitGenerator(
107
+ name="validation_matched",
108
+ # These kwargs will be passed to _generate_examples
109
+ gen_kwargs={
110
+ "filepath": os.path.join(data_dir, "multinli_tr_1.0_dev_matched.jsonl"),
111
+ "split": "dev",
112
+ },
113
+ ),
114
+ datasets.SplitGenerator(
115
+ name="validation_mismatched",
116
+ # These kwargs will be passed to _generate_examples
117
+ gen_kwargs={
118
+ "filepath": os.path.join(data_dir, "multinli_tr_1.0_dev_mismatched.jsonl"),
119
+ "split": "dev",
120
+ },
121
+ ),
122
+ ]
123
+
124
+ if self.config.name == "snli_tr":
125
+ return [
126
+ datasets.SplitGenerator(
127
+ name=datasets.Split.TRAIN,
128
+ # These kwargs will be passed to _generate_examples
129
+ gen_kwargs={
130
+ "filepath": os.path.join(data_dir, "snli_tr_1.0_train.jsonl"),
131
+ "split": "train",
132
+ },
133
+ ),
134
+ datasets.SplitGenerator(
135
+ name=datasets.Split.VALIDATION,
136
+ # These kwargs will be passed to _generate_examples
137
+ gen_kwargs={
138
+ "filepath": os.path.join(data_dir, "snli_tr_1.0_dev.jsonl"),
139
+ "split": "validation",
140
+ },
141
+ ),
142
+ datasets.SplitGenerator(
143
+ name=datasets.Split.TEST,
144
+ # These kwargs will be passed to _generate_examples
145
+ gen_kwargs={
146
+ "filepath": os.path.join(data_dir, "snli_tr_1.0_test.jsonl"),
147
+ "split": "test",
148
+ },
149
+ ),
150
+ ]
151
+
152
+ def _generate_examples(self, filepath, split):
153
+ """Yields examples."""
154
+
155
+ with codecs.open(filepath, encoding="utf-8") as f:
156
+ for idx, row in enumerate(f):
157
+ data = json.loads(row)
158
+ example = {"idx": idx, "premise": data["sentence1"], "hypothesis": data["sentence2"]}
159
+
160
+ if "gold_label" in data:
161
+ if data["gold_label"] != "-":
162
+ example["label"] = data["gold_label"]
163
+ else:
164
+ example["label"] = -1
165
+
166
+ yield idx, example