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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 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 |
+
|
16 |
+
from pathlib import Path
|
17 |
+
from typing import Dict, List, Tuple
|
18 |
+
|
19 |
+
import datasets
|
20 |
+
|
21 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
22 |
+
from seacrowd.utils.constants import (SCHEMA_TO_FEATURES, TASK_TO_SCHEMA,
|
23 |
+
Licenses, Tasks)
|
24 |
+
|
25 |
+
_CITATION = """\
|
26 |
+
@inproceedings{mayhew-etal-2020-simultaneous,
|
27 |
+
title = "Simultaneous Translation and Paraphrase for Language Education",
|
28 |
+
author = "Mayhew, Stephen and
|
29 |
+
Bicknell, Klinton and
|
30 |
+
Brust, Chris and
|
31 |
+
McDowell, Bill and
|
32 |
+
Monroe, Will and
|
33 |
+
Settles, Burr",
|
34 |
+
editor = "Birch, Alexandra and
|
35 |
+
Finch, Andrew and
|
36 |
+
Hayashi, Hiroaki and
|
37 |
+
Heafield, Kenneth and
|
38 |
+
Junczys-Dowmunt, Marcin and
|
39 |
+
Konstas, Ioannis and
|
40 |
+
Li, Xian and
|
41 |
+
Neubig, Graham and
|
42 |
+
Oda, Yusuke",
|
43 |
+
booktitle = "Proceedings of the Fourth Workshop on Neural Generation and Translation",
|
44 |
+
month = jul,
|
45 |
+
year = "2020",
|
46 |
+
address = "Online",
|
47 |
+
publisher = "Association for Computational Linguistics",
|
48 |
+
url = "https://aclanthology.org/2020.ngt-1.28",
|
49 |
+
doi = "10.18653/v1/2020.ngt-1.28",
|
50 |
+
pages = "232--243",
|
51 |
+
}
|
52 |
+
"""
|
53 |
+
|
54 |
+
_DATASETNAME = "duolingo_staple_2020"
|
55 |
+
|
56 |
+
_DESCRIPTION = """\
|
57 |
+
This dataset is provided by Duolingo for their Simultaneous Translation and
|
58 |
+
Paraphrase for Language Education (STAPLE) shared task in 2020. It contains
|
59 |
+
English prompts and corresponding sets of plausible translations in five other
|
60 |
+
languages, including Vietnamese. Each prompt is provided with a baseline
|
61 |
+
automatic reference translation from Amazon, as well as some accepted
|
62 |
+
translations with corresponding user response rates used for task scoring.
|
63 |
+
"""
|
64 |
+
|
65 |
+
_HOMEPAGE = "https://sharedtask.duolingo.com/#data"
|
66 |
+
|
67 |
+
_LANGUAGES = ["vie"]
|
68 |
+
|
69 |
+
_LICENSE = Licenses.CC_BY_NC_4_0.value
|
70 |
+
|
71 |
+
_LOCAL = True # needs to fill a form to download the dataset (dynamic link)
|
72 |
+
|
73 |
+
_URLS = "https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/38OJR6&version=6.0"
|
74 |
+
|
75 |
+
# `aws_baseline` refers to reference translations from Amazon Automated MT model,
|
76 |
+
# while `gold` refers to translations accepted by Duolingo learners
|
77 |
+
_SUBSETS = ["aws_baseline", "gold"]
|
78 |
+
|
79 |
+
_SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]
|
80 |
+
_SEACROWD_SCHEMA = f"seacrowd_{TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]].lower()}" # t2t
|
81 |
+
|
82 |
+
_SOURCE_VERSION = "6.0.0"
|
83 |
+
|
84 |
+
_SEACROWD_VERSION = "2024.06.20"
|
85 |
+
|
86 |
+
|
87 |
+
class DuolingoStaple2020Dataset(datasets.GeneratorBasedBuilder):
|
88 |
+
"""Dataset for the Duolingo STAPLE 2020 shared task."""
|
89 |
+
|
90 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
91 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
92 |
+
|
93 |
+
BUILDER_CONFIGS = []
|
94 |
+
for subset in _SUBSETS:
|
95 |
+
BUILDER_CONFIGS += [
|
96 |
+
SEACrowdConfig(
|
97 |
+
name=f"{_DATASETNAME}_{subset}_source",
|
98 |
+
version=SOURCE_VERSION,
|
99 |
+
description=f"{_DATASETNAME} {subset} source schema",
|
100 |
+
schema="source",
|
101 |
+
subset_id=subset,
|
102 |
+
),
|
103 |
+
SEACrowdConfig(
|
104 |
+
name=f"{_DATASETNAME}_{subset}_{_SEACROWD_SCHEMA}",
|
105 |
+
version=SEACROWD_VERSION,
|
106 |
+
description=f"{_DATASETNAME} {subset} SEACrowd schema",
|
107 |
+
schema=_SEACROWD_SCHEMA,
|
108 |
+
subset_id=subset,
|
109 |
+
),
|
110 |
+
]
|
111 |
+
|
112 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_gold_source"
|
113 |
+
|
114 |
+
def _info(self) -> datasets.DatasetInfo:
|
115 |
+
if self.config.schema == "source":
|
116 |
+
if self.config.subset_id == "aws_baseline":
|
117 |
+
features = datasets.Features(
|
118 |
+
{
|
119 |
+
"prompt_id": datasets.Value("string"),
|
120 |
+
"source_text": datasets.Value("string"),
|
121 |
+
"translation": datasets.Value("string"),
|
122 |
+
}
|
123 |
+
)
|
124 |
+
elif self.config.subset_id == "gold":
|
125 |
+
features = datasets.Features(
|
126 |
+
{
|
127 |
+
"prompt_id": datasets.Value("string"),
|
128 |
+
"source_text": datasets.Value("string"),
|
129 |
+
"translations": [
|
130 |
+
{
|
131 |
+
"text": datasets.Value("string"),
|
132 |
+
"weight": datasets.Value("float64"),
|
133 |
+
}
|
134 |
+
],
|
135 |
+
}
|
136 |
+
)
|
137 |
+
elif self.config.schema == _SEACROWD_SCHEMA:
|
138 |
+
features = SCHEMA_TO_FEATURES[TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]]] # text2text_features
|
139 |
+
|
140 |
+
return datasets.DatasetInfo(
|
141 |
+
description=_DESCRIPTION,
|
142 |
+
features=features,
|
143 |
+
homepage=_HOMEPAGE,
|
144 |
+
license=_LICENSE,
|
145 |
+
citation=_CITATION,
|
146 |
+
)
|
147 |
+
|
148 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
149 |
+
"""Returns SplitGenerators."""
|
150 |
+
if self.config.data_dir is None:
|
151 |
+
raise ValueError("This is a local dataset. Please pass the data_dir kwarg (staple-2020 dir) to load_dataset.")
|
152 |
+
else:
|
153 |
+
data_dir = Path(self.config.data_dir) / "en_vi"
|
154 |
+
|
155 |
+
if self.config.subset_id == "aws_baseline":
|
156 |
+
filename = "aws_baseline.pred"
|
157 |
+
elif self.config.subset_id == "gold":
|
158 |
+
filename = "2020-02-20.gold"
|
159 |
+
|
160 |
+
return [
|
161 |
+
datasets.SplitGenerator(
|
162 |
+
name=datasets.Split.TRAIN,
|
163 |
+
gen_kwargs={
|
164 |
+
"filepath": data_dir / f"train.en_vi.{'2020-01-13.gold' if self.config.subset_id == 'gold' else filename}.txt",
|
165 |
+
},
|
166 |
+
),
|
167 |
+
datasets.SplitGenerator(
|
168 |
+
name=datasets.Split.TEST,
|
169 |
+
gen_kwargs={
|
170 |
+
"filepath": data_dir / f"test.en_vi.{filename}.txt",
|
171 |
+
},
|
172 |
+
),
|
173 |
+
datasets.SplitGenerator(
|
174 |
+
name=datasets.Split.VALIDATION,
|
175 |
+
gen_kwargs={
|
176 |
+
"filepath": data_dir / f"dev.en_vi.{filename}.txt",
|
177 |
+
},
|
178 |
+
),
|
179 |
+
]
|
180 |
+
|
181 |
+
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
182 |
+
"""Yields examples as (key, example) tuples."""
|
183 |
+
# aws_baseline subset
|
184 |
+
if self.config.subset_id == "aws_baseline":
|
185 |
+
with open(filepath, "r", encoding="utf-8") as f:
|
186 |
+
entries = f.read().strip().split("\n\n")
|
187 |
+
|
188 |
+
for key, entry in enumerate(entries):
|
189 |
+
parts = entry.split("|")
|
190 |
+
prompt_id = parts[0].strip()
|
191 |
+
source_text, translation = list(map(str.strip, parts[1].split("\n")))
|
192 |
+
|
193 |
+
if self.config.schema == "source":
|
194 |
+
yield key, {
|
195 |
+
"prompt_id": prompt_id,
|
196 |
+
"source_text": source_text,
|
197 |
+
"translation": translation,
|
198 |
+
}
|
199 |
+
elif self.config.schema == _SEACROWD_SCHEMA:
|
200 |
+
yield key, {
|
201 |
+
"id": str(key),
|
202 |
+
"text_1": source_text,
|
203 |
+
"text_2": translation,
|
204 |
+
"text_1_name": "english",
|
205 |
+
"text_2_name": "translation",
|
206 |
+
}
|
207 |
+
|
208 |
+
# gold subset
|
209 |
+
elif self.config.subset_id == "gold":
|
210 |
+
with open(filepath, "r", encoding="utf-8") as f:
|
211 |
+
entries = f.read().strip().split("\n\n")
|
212 |
+
|
213 |
+
key = 0
|
214 |
+
for entry in entries:
|
215 |
+
parts = entry.split("\n")
|
216 |
+
prompt_id, source_text = list(map(str.strip, parts[0].split("|")))
|
217 |
+
|
218 |
+
if self.config.schema == "source":
|
219 |
+
translations = []
|
220 |
+
for answer in parts[1:]:
|
221 |
+
translation, weight = list(map(str.strip, answer.split("|")))
|
222 |
+
translations.append({"text": translation, "weight": float(weight)})
|
223 |
+
yield key, {
|
224 |
+
"prompt_id": prompt_id,
|
225 |
+
"source_text": source_text,
|
226 |
+
"translations": translations,
|
227 |
+
}
|
228 |
+
key += 1
|
229 |
+
|
230 |
+
elif self.config.schema == _SEACROWD_SCHEMA:
|
231 |
+
for answer in parts[1:]:
|
232 |
+
translation, _ = list(map(str.strip, answer.split("|")))
|
233 |
+
yield key, {
|
234 |
+
"id": str(key),
|
235 |
+
"text_1": source_text,
|
236 |
+
"text_2": translation,
|
237 |
+
"text_1_name": "english",
|
238 |
+
"text_2_name": "translation",
|
239 |
+
}
|
240 |
+
key += 1
|