Commit
•
d1fb0b2
1
Parent(s):
d310843
Delete loading script
Browse files
chr_en.py
DELETED
@@ -1,202 +0,0 @@
|
|
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 |
-
"""ChrEn: Cherokee-English Machine Translation data"""
|
16 |
-
|
17 |
-
|
18 |
-
import openpyxl # noqa: requires this pandas optional dependency for reading xlsx files
|
19 |
-
import pandas as pd
|
20 |
-
|
21 |
-
import datasets
|
22 |
-
|
23 |
-
|
24 |
-
_CITATION = """\
|
25 |
-
@inproceedings{zhang2020chren,
|
26 |
-
title={ChrEn: Cherokee-English Machine Translation for Endangered Language Revitalization},
|
27 |
-
author={Zhang, Shiyue and Frey, Benjamin and Bansal, Mohit},
|
28 |
-
booktitle={EMNLP2020},
|
29 |
-
year={2020}
|
30 |
-
}
|
31 |
-
"""
|
32 |
-
|
33 |
-
_DESCRIPTION = """\
|
34 |
-
ChrEn is a Cherokee-English parallel dataset to facilitate machine translation research between Cherokee and English.
|
35 |
-
ChrEn is extremely low-resource contains 14k sentence pairs in total, split in ways that facilitate both in-domain and out-of-domain evaluation.
|
36 |
-
ChrEn also contains 5k Cherokee monolingual data to enable semi-supervised learning.
|
37 |
-
"""
|
38 |
-
|
39 |
-
_HOMEPAGE = "https://github.com/ZhangShiyue/ChrEn"
|
40 |
-
|
41 |
-
_LICENSE = ""
|
42 |
-
|
43 |
-
_URLs = {
|
44 |
-
"monolingual_raw": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/raw/monolingual_data.xlsx",
|
45 |
-
"parallel_raw": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/raw/parallel_data.xlsx",
|
46 |
-
"monolingual_chr": "https://raw.githubusercontent.com/ZhangShiyue/ChrEn/main/data/monolingual/chr",
|
47 |
-
"monolingual_en5000": "https://raw.githubusercontent.com/ZhangShiyue/ChrEn/main/data/monolingual/en5000",
|
48 |
-
"monolingual_en10000": "https://raw.githubusercontent.com/ZhangShiyue/ChrEn/main/data/monolingual/en10000",
|
49 |
-
"monolingual_en20000": "https://raw.githubusercontent.com/ZhangShiyue/ChrEn/main/data/monolingual/en20000",
|
50 |
-
"monolingual_en50000": "https://raw.githubusercontent.com/ZhangShiyue/ChrEn/main/data/monolingual/en50000",
|
51 |
-
"monolingual_en100000": "https://raw.githubusercontent.com/ZhangShiyue/ChrEn/main/data/monolingual/en100000",
|
52 |
-
"parallel_train.chr": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/train.chr",
|
53 |
-
"parallel_train.en": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/train.en",
|
54 |
-
"parallel_dev.chr": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/dev.chr",
|
55 |
-
"parallel_dev.en": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/dev.en",
|
56 |
-
"parallel_out_dev.chr": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/out_dev.chr",
|
57 |
-
"parallel_out_dev.en": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/out_dev.en",
|
58 |
-
"parallel_test.chr": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/test.chr",
|
59 |
-
"parallel_test.en": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/test.en",
|
60 |
-
"parallel_out_test.chr": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/out_test.chr",
|
61 |
-
"parallel_out_test.en": "https://github.com/ZhangShiyue/ChrEn/raw/main/data/parallel/out_test.en",
|
62 |
-
}
|
63 |
-
|
64 |
-
|
65 |
-
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
66 |
-
class ChrEn(datasets.GeneratorBasedBuilder):
|
67 |
-
"""ChrEn: Cherokee-English Machine Translation data."""
|
68 |
-
|
69 |
-
VERSION = datasets.Version("1.0.0")
|
70 |
-
|
71 |
-
BUILDER_CONFIGS = [
|
72 |
-
datasets.BuilderConfig(name="monolingual_raw", version=VERSION, description="Monolingual data with metadata"),
|
73 |
-
datasets.BuilderConfig(name="parallel_raw", version=VERSION, description="Parallel data with metadata"),
|
74 |
-
datasets.BuilderConfig(name="monolingual", version=VERSION, description="Monolingual data text only"),
|
75 |
-
datasets.BuilderConfig(
|
76 |
-
name="parallel", version=VERSION, description="Parallel data text pairs only with default split"
|
77 |
-
),
|
78 |
-
]
|
79 |
-
|
80 |
-
DEFAULT_CONFIG_NAME = (
|
81 |
-
"parallel" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
82 |
-
)
|
83 |
-
|
84 |
-
def _info(self):
|
85 |
-
if (
|
86 |
-
self.config.name == "monolingual_raw"
|
87 |
-
): # This is the name of the configuration selected in BUILDER_CONFIGS above
|
88 |
-
features = datasets.Features(
|
89 |
-
{
|
90 |
-
"text_sentence": datasets.Value("string"),
|
91 |
-
"text_title": datasets.Value("string"),
|
92 |
-
"speaker": datasets.Value("string"),
|
93 |
-
"date": datasets.Value("int32"),
|
94 |
-
"type": datasets.Value("string"),
|
95 |
-
"dialect": datasets.Value("string"),
|
96 |
-
}
|
97 |
-
)
|
98 |
-
elif (
|
99 |
-
self.config.name == "parallel_raw"
|
100 |
-
): # This is the name of the configuration selected in BUILDER_CONFIGS above
|
101 |
-
features = datasets.Features(
|
102 |
-
{
|
103 |
-
"line_number": datasets.Value("string"), # doesn't always map to a number
|
104 |
-
"sentence_pair": datasets.Translation(languages=["en", "chr"]),
|
105 |
-
"text_title": datasets.Value("string"),
|
106 |
-
"speaker": datasets.Value("string"),
|
107 |
-
"date": datasets.Value("int32"),
|
108 |
-
"type": datasets.Value("string"),
|
109 |
-
"dialect": datasets.Value("string"),
|
110 |
-
}
|
111 |
-
)
|
112 |
-
elif (
|
113 |
-
self.config.name == "parallel"
|
114 |
-
): # This is an example to show how to have different features for "first_domain" and "second_domain"
|
115 |
-
features = datasets.Features(
|
116 |
-
{
|
117 |
-
"sentence_pair": datasets.Translation(languages=["en", "chr"]),
|
118 |
-
}
|
119 |
-
)
|
120 |
-
elif (
|
121 |
-
self.config.name == "monolingual"
|
122 |
-
): # This is an example to show how to have different features for "first_domain" and "second_domain"
|
123 |
-
features = datasets.Features(
|
124 |
-
{
|
125 |
-
"sentence": datasets.Value("string"),
|
126 |
-
}
|
127 |
-
)
|
128 |
-
return datasets.DatasetInfo(
|
129 |
-
description=_DESCRIPTION,
|
130 |
-
features=features, # Here we define them above because they are different between the two configurations
|
131 |
-
supervised_keys=None,
|
132 |
-
homepage=_HOMEPAGE,
|
133 |
-
license=_LICENSE,
|
134 |
-
citation=_CITATION,
|
135 |
-
)
|
136 |
-
|
137 |
-
def _split_generators(self, dl_manager):
|
138 |
-
"""Returns SplitGenerators."""
|
139 |
-
data_dir = dl_manager.download(_URLs)
|
140 |
-
if self.config.name in [
|
141 |
-
"monolingual_raw",
|
142 |
-
"parallel_raw",
|
143 |
-
]: # This is the name of the configuration selected in BUILDER_CONFIGS above
|
144 |
-
return [
|
145 |
-
datasets.SplitGenerator(
|
146 |
-
name="full",
|
147 |
-
gen_kwargs={
|
148 |
-
"filepaths": data_dir,
|
149 |
-
"split": "full",
|
150 |
-
},
|
151 |
-
)
|
152 |
-
]
|
153 |
-
elif self.config.name == "monolingual":
|
154 |
-
return [
|
155 |
-
datasets.SplitGenerator(
|
156 |
-
name=spl,
|
157 |
-
gen_kwargs={
|
158 |
-
"filepaths": data_dir,
|
159 |
-
"split": spl,
|
160 |
-
},
|
161 |
-
)
|
162 |
-
for spl in ["chr", "en5000", "en10000", "en20000", "en50000", "en100000"]
|
163 |
-
]
|
164 |
-
else:
|
165 |
-
return [
|
166 |
-
datasets.SplitGenerator(
|
167 |
-
name=spl,
|
168 |
-
gen_kwargs={
|
169 |
-
"filepaths": data_dir,
|
170 |
-
"split": spl,
|
171 |
-
},
|
172 |
-
)
|
173 |
-
for spl in ["train", "dev", "out_dev", "test", "out_test"]
|
174 |
-
]
|
175 |
-
|
176 |
-
def _generate_examples(self, filepaths, split):
|
177 |
-
if self.config.name == "monolingual_raw":
|
178 |
-
keys = ["text_sentence", "text_title", "speaker", "date", "type", "dialect"]
|
179 |
-
with open(filepaths["monolingual_raw"], "rb") as f:
|
180 |
-
monolingual = pd.read_excel(f, engine="openpyxl")
|
181 |
-
for id_, row in enumerate(monolingual.itertuples()):
|
182 |
-
yield id_, dict(zip(keys, row[1:]))
|
183 |
-
elif self.config.name == "parallel_raw":
|
184 |
-
keys = ["line_number", "en_sent", "chr_sent", "text_title", "speaker", "date", "type", "dialect"]
|
185 |
-
with open(filepaths["parallel_raw"], "rb") as f:
|
186 |
-
parallel = pd.read_excel(f, engine="openpyxl")
|
187 |
-
for id_, row in enumerate(parallel.itertuples()):
|
188 |
-
res = dict(zip(keys, row[1:]))
|
189 |
-
res["sentence_pair"] = {"en": res["en_sent"], "chr": res["chr_sent"]}
|
190 |
-
res["line_number"] = str(res["line_number"])
|
191 |
-
del res["en_sent"]
|
192 |
-
del res["chr_sent"]
|
193 |
-
yield id_, res
|
194 |
-
elif self.config.name == "monolingual":
|
195 |
-
f = open(filepaths[f"monolingual_{split}"], encoding="utf-8")
|
196 |
-
for id_, line in enumerate(f):
|
197 |
-
yield id_, {"sentence": line.strip()}
|
198 |
-
elif self.config.name == "parallel":
|
199 |
-
fi = open(filepaths[f"parallel_{split}.en"], encoding="utf-8")
|
200 |
-
fo = open(filepaths[f"parallel_{split}.chr"], encoding="utf-8")
|
201 |
-
for id_, (line_en, line_chr) in enumerate(zip(fi, fo)):
|
202 |
-
yield id_, {"sentence_pair": {"en": line_en.strip(), "chr": line_chr.strip()}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|