albertvillanova HF staff commited on
Commit
954b6fa
1 Parent(s): 7f826be

Convert dataset to Parquet (#3)

Browse files

- Convert dataset to Parquet (da9abc5fe22156e058e5469f43de34c7b7fa53aa)
- Add 'en2es' config data files (acac9f3acb590238d6fa57b70404804ef52aa453)
- Add 'en2fr' config data files (fe26a6020e2be24899e912c6605888ceae760769)
- Delete loading script (692be6f59a3c88e907fda82e987fdebd99f267b8)

README.md CHANGED
@@ -59,10 +59,10 @@ dataset_info:
59
  '1': sentence_data
60
  splits:
61
  - name: train
62
- num_bytes: 664252
63
  num_examples: 4061
64
- download_size: 3521416
65
- dataset_size: 664252
66
  - config_name: en2cs
67
  features:
68
  - name: translation
@@ -159,10 +159,10 @@ dataset_info:
159
  '1': sentence_data
160
  splits:
161
  - name: train
162
- num_bytes: 555218
163
  num_examples: 4303
164
- download_size: 3521416
165
- dataset_size: 555218
166
  - config_name: en2et
167
  features:
168
  - name: translation
@@ -219,10 +219,10 @@ dataset_info:
219
  '1': sentence_data
220
  splits:
221
  - name: train
222
- num_bytes: 575579
223
  num_examples: 4476
224
- download_size: 3521416
225
- dataset_size: 575579
226
  - config_name: en2hu
227
  features:
228
  - name: translation
@@ -523,6 +523,19 @@ dataset_info:
523
  num_examples: 3198
524
  download_size: 3521416
525
  dataset_size: 328267
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  ---
527
 
528
  # Dataset Card for Europa Education and Culture Translation Memory (EAC-TM)
 
59
  '1': sentence_data
60
  splits:
61
  - name: train
62
+ num_bytes: 664244
63
  num_examples: 4061
64
+ download_size: 332039
65
+ dataset_size: 664244
66
  - config_name: en2cs
67
  features:
68
  - name: translation
 
159
  '1': sentence_data
160
  splits:
161
  - name: train
162
+ num_bytes: 555210
163
  num_examples: 4303
164
+ download_size: 308680
165
+ dataset_size: 555210
166
  - config_name: en2et
167
  features:
168
  - name: translation
 
219
  '1': sentence_data
220
  splits:
221
  - name: train
222
+ num_bytes: 575571
223
  num_examples: 4476
224
+ download_size: 321064
225
+ dataset_size: 575571
226
  - config_name: en2hu
227
  features:
228
  - name: translation
 
523
  num_examples: 3198
524
  download_size: 3521416
525
  dataset_size: 328267
526
+ configs:
527
+ - config_name: en2bg
528
+ data_files:
529
+ - split: train
530
+ path: en2bg/train-*
531
+ - config_name: en2es
532
+ data_files:
533
+ - split: train
534
+ path: en2es/train-*
535
+ - config_name: en2fr
536
+ data_files:
537
+ - split: train
538
+ path: en2fr/train-*
539
  ---
540
 
541
  # Dataset Card for Europa Education and Culture Translation Memory (EAC-TM)
en2bg/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9de4205b34d914bbffa91fd28db9a51adaf762f56c1a970b29fd58f8d6c94b3a
3
+ size 332039
en2es/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b90ac0cc93ec7b3a385661b5c075a837dd5ec64236bf40430e29a1dbf913b1c
3
+ size 308680
en2fr/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a6e6c1d3c67a0f3d6afe881d83b2827efdefd2d64fb33a06ac4b3e3aa6b747a
3
+ size 321064
europa_eac_tm.py DELETED
@@ -1,226 +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
- """European commission Joint Reasearch Center's Education And Culture Translation Memory dataset"""
16
-
17
-
18
- import os
19
- from itertools import repeat
20
- from xml.etree import ElementTree
21
-
22
- import datasets
23
-
24
-
25
- _CITATION = """\
26
- @Article{Steinberger2014,
27
- author={Steinberger, Ralf
28
- and Ebrahim, Mohamed
29
- and Poulis, Alexandros
30
- and Carrasco-Benitez, Manuel
31
- and Schl{\"u}ter, Patrick
32
- and Przybyszewski, Marek
33
- and Gilbro, Signe},
34
- title={An overview of the European Union's highly multilingual parallel corpora},
35
- journal={Language Resources and Evaluation},
36
- year={2014},
37
- month={Dec},
38
- day={01},
39
- volume={48},
40
- number={4},
41
- pages={679-707},
42
- issn={1574-0218},
43
- doi={10.1007/s10579-014-9277-0},
44
- url={https://doi.org/10.1007/s10579-014-9277-0}
45
- }
46
- """
47
-
48
- _DESCRIPTION = """\
49
- In October 2012, the European Union's (EU) Directorate General for Education and Culture ( DG EAC) released a \
50
- translation memory (TM), i.e. a collection of sentences and their professionally produced translations, in \
51
- twenty-six languages. This resource bears the name EAC Translation Memory, short EAC-TM.
52
-
53
- EAC-TM covers up to 26 languages: 22 official languages of the EU (all except Irish) plus Icelandic, Croatian, \
54
- Norwegian and Turkish. EAC-TM thus contains translations from English into the following 25 languages: Bulgarian, \
55
- Czech, Danish, Dutch, Estonian, German, Greek, Finnish, French, Croatian, Hungarian, Icelandic, Italian, Latvian, \
56
- Lithuanian, Maltese, Norwegian, Polish, Portuguese, Romanian, Slovak, Slovenian, Spanish, Swedish and Turkish.
57
-
58
- All documents and sentences were originally written in English (source language is English) and then translated into \
59
- the other languages. The texts were translated by staff of the National Agencies of the Lifelong Learning and Youth in \
60
- Action programmes. They are typically professionals in the field of education/youth and EU programmes. They are thus not \
61
- professional translators, but they are normally native speakers of the target language.
62
- """
63
-
64
- _HOMEPAGE = "https://ec.europa.eu/jrc/en/language-technologies/eac-translation-memory"
65
-
66
- _LICENSE = "\
67
- Creative Commons Attribution 4.0 International(CC BY 4.0) licence \
68
- © European Union, 1995-2020"
69
-
70
- _VERSION = "1.0.0"
71
-
72
- _DATA_URL = "https://wt-public.emm4u.eu/Resources/EAC-TM/EAC-TM-all.zip"
73
-
74
- _AVAILABLE_LANGUAGES = (
75
- "bg",
76
- "cs",
77
- "da",
78
- "de",
79
- "el",
80
- "en",
81
- "es",
82
- "et",
83
- "fi",
84
- "fr",
85
- "hu",
86
- "is",
87
- "it",
88
- "lt",
89
- "lv",
90
- "mt",
91
- "nb",
92
- "nl",
93
- "pl",
94
- "pt",
95
- "ro",
96
- "sk",
97
- "sl",
98
- "sv",
99
- "tr",
100
- )
101
-
102
-
103
- def _find_sentence(translation, language):
104
- """Util that returns the sentence in the given language from translation, or None if it is not found
105
-
106
- Args:
107
- translation: `xml.etree.ElementTree.Element`, xml tree element extracted from the translation memory files.
108
- language: `str`, language of interest e.g. 'en'
109
-
110
- Returns: `str` or `None`, can be `None` if the language of interest is not found in the translation
111
- """
112
- # Retrieve the first <tuv> children of translation having xml:lang tag equal to language
113
- namespaces = {"xml": "http://www.w3.org/XML/1998/namespace"}
114
- seg_tag = translation.find(path=f".//tuv[@xml:lang='{language}']/seg", namespaces=namespaces)
115
- if seg_tag is not None:
116
- return seg_tag.text
117
- return None
118
-
119
-
120
- class EuropaEacTMConfig(datasets.BuilderConfig):
121
- """BuilderConfig for EuropaEacTM"""
122
-
123
- def __init__(self, *args, language_pair=(None, None), **kwargs):
124
- """BuilderConfig for EuropaEacTM
125
-
126
- Args:
127
- language_pair: pair of languages that will be used for translation. Should
128
- contain 2-letter coded strings. First will be used at source and second
129
- as target in supervised mode. For example: ("ro", "en").
130
- **kwargs: keyword arguments forwarded to super.
131
- """
132
- name = f"{language_pair[0]}2{language_pair[1]}"
133
- description = f"Translation dataset from {language_pair[0]} to {language_pair[1]}"
134
- super(EuropaEacTMConfig, self).__init__(
135
- *args,
136
- name=name,
137
- description=description,
138
- **kwargs,
139
- )
140
- source, target = language_pair
141
- assert source != target, "Source and target languages must be different}"
142
- assert (source in _AVAILABLE_LANGUAGES) and (
143
- target in _AVAILABLE_LANGUAGES
144
- ), f"Either source language {source} or target language {target} is not supported. Both must be one of : {_AVAILABLE_LANGUAGES}"
145
-
146
- self.language_pair = language_pair
147
-
148
-
149
- # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
150
- class EuropaEacTM(datasets.GeneratorBasedBuilder):
151
- """European Commission Joint Research Center's EAC Translation Memory"""
152
-
153
- FORM_SENTENCE_TYPE = "form_data"
154
- REFERENCE_SENTENCE_TYPE = "sentence_data"
155
-
156
- # Only a few language pairs are listed here. You can use config to generate all language pairs !
157
- BUILDER_CONFIGS = [
158
- EuropaEacTMConfig(language_pair=("en", target), version=_VERSION) for target in ["bg", "es", "fr"]
159
- ]
160
- BUILDER_CONFIG_CLASS = EuropaEacTMConfig
161
-
162
- def _info(self):
163
- source, target = self.config.language_pair
164
- return datasets.DatasetInfo(
165
- description=_DESCRIPTION,
166
- features=datasets.Features(
167
- {
168
- "translation": datasets.features.Translation(languages=self.config.language_pair),
169
- "sentence_type": datasets.features.ClassLabel(
170
- names=[self.FORM_SENTENCE_TYPE, self.REFERENCE_SENTENCE_TYPE]
171
- ),
172
- }
173
- ),
174
- supervised_keys=(source, target),
175
- homepage=_HOMEPAGE,
176
- license=_LICENSE,
177
- citation=_CITATION,
178
- )
179
-
180
- def _split_generators(self, dl_manager):
181
- dl_dir = dl_manager.download_and_extract(_DATA_URL)
182
- form_data_file = os.path.join(dl_dir, "EAC_FORMS.tmx")
183
- reference_data_file = os.path.join(dl_dir, "EAC_REFRENCE_DATA.tmx")
184
- source, target = self.config.language_pair
185
- return [
186
- datasets.SplitGenerator(
187
- name=datasets.Split.TRAIN,
188
- gen_kwargs={
189
- "form_data_file": form_data_file,
190
- "reference_data_file": reference_data_file,
191
- "source_language": source,
192
- "target_language": target,
193
- },
194
- ),
195
- ]
196
-
197
- def _generate_examples(
198
- self,
199
- form_data_file,
200
- reference_data_file,
201
- source_language,
202
- target_language,
203
- ):
204
- _id = 0
205
- for (sentence_type, filepath) in [
206
- (self.FORM_SENTENCE_TYPE, form_data_file),
207
- (self.REFERENCE_SENTENCE_TYPE, reference_data_file),
208
- ]:
209
- # Retrieve <tu></tu> tags in the tmx file
210
- xml_element_tree = ElementTree.parse(filepath)
211
- xml_body_tag = xml_element_tree.getroot().find("body")
212
- assert xml_body_tag is not None, f"Invalid data: <body></body> tag not found in {filepath}"
213
- translation_units = xml_body_tag.iter("tu")
214
-
215
- # Pair sentence_type and translation_units
216
- for sentence_type, translation in zip(repeat(sentence_type), translation_units):
217
- source_sentence = _find_sentence(translation=translation, language=source_language)
218
- target_sentence = _find_sentence(translation=translation, language=target_language)
219
- if source_sentence is None or target_sentence is None:
220
- continue
221
- _id += 1
222
- sentence_label = 0 if sentence_type == self.FORM_SENTENCE_TYPE else 1
223
- yield _id, {
224
- "translation": {source_language: source_sentence, target_language: target_sentence},
225
- "sentence_type": sentence_label,
226
- }