Convert dataset to Parquet

#2
by albertvillanova HF staff - opened
README.md CHANGED
@@ -40,7 +40,6 @@ source_datasets:
40
  task_categories:
41
  - translation
42
  task_ids: []
43
- paperswithcode_id: null
44
  pretty_name: EuropaEcdcTm
45
  dataset_info:
46
  - config_name: en2bg
@@ -53,10 +52,10 @@ dataset_info:
53
  - bg
54
  splits:
55
  - name: train
56
- num_bytes: 798444
57
  num_examples: 2567
58
- download_size: 4286636
59
- dataset_size: 798444
60
  - config_name: en2cs
61
  features:
62
  - name: translation
@@ -165,10 +164,10 @@ dataset_info:
165
  - fr
166
  splits:
167
  - name: train
168
- num_bytes: 595489
169
  num_examples: 2561
170
- download_size: 4286636
171
- dataset_size: 595489
172
  - config_name: en2ga
173
  features:
174
  - name: translation
@@ -361,10 +360,10 @@ dataset_info:
361
  - sl
362
  splits:
363
  - name: train
364
- num_bytes: 594027
365
  num_examples: 2545
366
- download_size: 4286636
367
- dataset_size: 594027
368
  - config_name: en2sv
369
  features:
370
  - name: translation
@@ -379,6 +378,19 @@ dataset_info:
379
  num_examples: 2527
380
  download_size: 4286636
381
  dataset_size: 546349
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  ---
383
 
384
  # Dataset Card for [Dataset Name]
 
40
  task_categories:
41
  - translation
42
  task_ids: []
 
43
  pretty_name: EuropaEcdcTm
44
  dataset_info:
45
  - config_name: en2bg
 
52
  - bg
53
  splits:
54
  - name: train
55
+ num_bytes: 798436
56
  num_examples: 2567
57
+ download_size: 382582
58
+ dataset_size: 798436
59
  - config_name: en2cs
60
  features:
61
  - name: translation
 
164
  - fr
165
  splits:
166
  - name: train
167
+ num_bytes: 595481
168
  num_examples: 2561
169
+ download_size: 327758
170
+ dataset_size: 595481
171
  - config_name: en2ga
172
  features:
173
  - name: translation
 
360
  - sl
361
  splits:
362
  - name: train
363
+ num_bytes: 594019
364
  num_examples: 2545
365
+ download_size: 319355
366
+ dataset_size: 594019
367
  - config_name: en2sv
368
  features:
369
  - name: translation
 
378
  num_examples: 2527
379
  download_size: 4286636
380
  dataset_size: 546349
381
+ configs:
382
+ - config_name: en2bg
383
+ data_files:
384
+ - split: train
385
+ path: en2bg/train-*
386
+ - config_name: en2fr
387
+ data_files:
388
+ - split: train
389
+ path: en2fr/train-*
390
+ - config_name: en2sl
391
+ data_files:
392
+ - split: train
393
+ path: en2sl/train-*
394
  ---
395
 
396
  # Dataset Card for [Dataset Name]
en2bg/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ce9864cc1a94e065928407d3672e5cea333e6db5322a8f7196c17c54bf432cf
3
+ size 382582
en2fr/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5eb0e32a48fbfbaf1d3ee4cd422e2226e522811a79b9bbc6d7b7e11fc02746cf
3
+ size 327758
en2sl/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25322ac5b1ffdad4ad9f07c272a3edcb4e4a8c2616a8a8dad5f2450b5398bcb7
3
+ size 319355
europa_ecdc_tm.py DELETED
@@ -1,206 +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 Center for Disease Prevention and Control Translation Memory dataset"""
16
-
17
-
18
- import os
19
- from xml.etree import ElementTree
20
-
21
- import datasets
22
-
23
-
24
- logger = datasets.logging.get_logger(__name__)
25
-
26
-
27
- _CITATION = """\
28
- @Article{Steinberger2014,
29
- author={Steinberger, Ralf
30
- and Ebrahim, Mohamed
31
- and Poulis, Alexandros
32
- and Carrasco-Benitez, Manuel
33
- and Schl{\"u}ter, Patrick
34
- and Przybyszewski, Marek
35
- and Gilbro, Signe},
36
- title={An overview of the European Union's highly multilingual parallel corpora},
37
- journal={Language Resources and Evaluation},
38
- year={2014},
39
- month={Dec},
40
- day={01},
41
- volume={48},
42
- number={4},
43
- pages={679-707},
44
- issn={1574-0218},
45
- doi={10.1007/s10579-014-9277-0},
46
- url={https://doi.org/10.1007/s10579-014-9277-0}
47
- }
48
- """
49
-
50
- _DESCRIPTION = """\
51
- In October 2012, the European Union (EU) agency 'European Centre for Disease Prevention and Control' (ECDC) released \
52
- a translation memory (TM), i.e. a collection of sentences and their professionally produced translations, in \
53
- twenty-five languages. This resource bears the name EAC Translation Memory, short EAC-TM.
54
- ECDC-TM covers 25 languages: the 23 official languages of the EU plus Norwegian (Norsk) and Icelandic. ECDC-TM was \
55
- created by translating from English into the following 24 languages: Bulgarian, Czech, Danish, Dutch, English, \
56
- Estonian, Gaelige (Irish), German, Greek, Finnish, French, Hungarian, Icelandic, Italian, Latvian, Lithuanian, \
57
- Maltese, Norwegian (NOrsk), Polish, Portuguese, Romanian, Slovak, Slovenian, Spanish and Swedish.
58
- All documents and sentences were thus originally written in English. They were then translated into the other \
59
- languages by professional translators from the Translation Centre CdT in Luxembourg."""
60
-
61
- _HOMEPAGE = "https://ec.europa.eu/jrc/en/language-technologies/ecdc-translation-memory"
62
-
63
- _LICENSE = "\
64
- Creative Commons Attribution 4.0 International(CC BY 4.0) licence \
65
- Copyright © EU/ECDC, 1995-2020"
66
-
67
- _VERSION = "1.0.0"
68
-
69
- _DATA_URL = "http://optima.jrc.it/Resources/ECDC-TM/ECDC-TM.zip"
70
-
71
- _AVAILABLE_LANGUAGES = (
72
- "bg",
73
- "cs",
74
- "da",
75
- "de",
76
- "el",
77
- "es",
78
- "en",
79
- "et",
80
- "fi",
81
- "fr",
82
- "ga",
83
- "hu",
84
- "is",
85
- "it",
86
- "lt",
87
- "lv",
88
- "mt",
89
- "nl",
90
- "no",
91
- "pl",
92
- "pt",
93
- "ro",
94
- "sk",
95
- "sl",
96
- "sv",
97
- )
98
-
99
-
100
- def _find_sentence(translation, language):
101
- """Util that returns the sentence in the given language from translation, or None if it is not found
102
-
103
- Args:
104
- translation: `xml.etree.ElementTree.Element`, xml tree element extracted from the translation memory files.
105
- language: `str`, language of interest e.g. 'en'
106
-
107
- Returns: `str` or `None`, can be `None` if the language of interest is not found in the translation
108
- """
109
- # Retrieve the first <tuv> children of translation having xml:lang tag equal to language
110
- namespaces = {"xml": "http://www.w3.org/XML/1998/namespace"}
111
- seg_tag = translation.find(path=f".//tuv[@xml:lang='{language.upper()}']/seg", namespaces=namespaces)
112
- if seg_tag is not None:
113
- return seg_tag.text
114
- return None
115
-
116
-
117
- class EuropaEcdcTMConfig(datasets.BuilderConfig):
118
- """BuilderConfig for EuropaEcdcTM"""
119
-
120
- def __init__(self, *args, language_pair=(None, None), **kwargs):
121
- """BuilderConfig for EuropaEcdcTM
122
- Args:
123
- language_pair: pair of languages that will be used for translation. Should
124
- contain 2-letter coded strings. First will be used at source and second
125
- as target in supervised mode. For example: ("se", "en").
126
- **kwargs: keyword arguments forwarded to super.
127
- """
128
- name = f"{language_pair[0]}2{language_pair[1]}"
129
- description = f"Translation dataset from {language_pair[0]} to {language_pair[1]}"
130
- super(EuropaEcdcTMConfig, self).__init__(
131
- *args,
132
- name=name,
133
- description=description,
134
- **kwargs,
135
- )
136
- source, target = language_pair
137
- assert source != target, "Source and target languages must be different}"
138
- assert (source in _AVAILABLE_LANGUAGES) and (
139
- target in _AVAILABLE_LANGUAGES
140
- ), f"Either source language {source} or target language {target} is not supported. Both must be one of : {_AVAILABLE_LANGUAGES}"
141
- self.language_pair = language_pair
142
-
143
-
144
- # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
145
- class EuropaEcdcTM(datasets.GeneratorBasedBuilder):
146
- """European Center for Disease Control and Prevention Translation Memory"""
147
-
148
- BUILDER_CONFIGS = [
149
- EuropaEcdcTMConfig(language_pair=("en", target), version=_VERSION) for target in ["bg", "fr", "sl"]
150
- ]
151
- BUILDER_CONFIG_CLASS = EuropaEcdcTMConfig
152
-
153
- def _info(self):
154
- source, target = self.config.language_pair
155
- return datasets.DatasetInfo(
156
- description=_DESCRIPTION,
157
- features=datasets.Features(
158
- {
159
- "translation": datasets.features.Translation(languages=self.config.language_pair),
160
- }
161
- ),
162
- supervised_keys=(source, target),
163
- homepage=_HOMEPAGE,
164
- license=_LICENSE,
165
- citation=_CITATION,
166
- )
167
-
168
- def _split_generators(self, dl_manager):
169
- dl_dir = dl_manager.download_and_extract(_DATA_URL)
170
- filepath = os.path.join(dl_dir, "ECDC-TM", "ECDC.tmx")
171
- source, target = self.config.language_pair
172
- return [
173
- datasets.SplitGenerator(
174
- name=datasets.Split.TRAIN,
175
- gen_kwargs={
176
- "filepath": filepath,
177
- "source_language": source,
178
- "target_language": target,
179
- },
180
- ),
181
- ]
182
-
183
- def _generate_examples(
184
- self,
185
- filepath,
186
- source_language,
187
- target_language,
188
- ):
189
- logger.info(f"⏳ Generating examples from = {filepath}")
190
- xml_element_tree = ElementTree.parse(filepath)
191
- xml_body_tag = xml_element_tree.getroot().find("body")
192
- assert xml_body_tag is not None, f"Invalid data: <body></body> tag not found in {filepath}"
193
-
194
- # Translations are stored in <tu>...</tu> tags
195
- translation_units = xml_body_tag.iter("tu")
196
-
197
- # _ids may not be contiguous
198
- for _id, translation in enumerate(translation_units):
199
- source_sentence = _find_sentence(translation=translation, language=source_language)
200
- target_sentence = _find_sentence(translation=translation, language=target_language)
201
- if source_sentence is None or target_sentence is None:
202
- continue
203
-
204
- yield _id, {
205
- "translation": {source_language: source_sentence, target_language: target_sentence},
206
- }