Datasets:
Delete loading script
Browse files
un_ga.py
DELETED
|
@@ -1,154 +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 |
-
"""United nations general assembly resolutions: A six-language parallel corpus"""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
import os
|
| 19 |
-
|
| 20 |
-
import datasets
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
_CITATION = """\
|
| 24 |
-
@inproceedings{title = "United Nations General Assembly Resolutions: a six-language parallel corpus",
|
| 25 |
-
abstract = "In this paper we describe a six-ways parallel public-domain corpus consisting of 2100 United Nations General Assembly Resolutions with translations in the six official languages of the United Nations, with an average of around 3 million tokens per language. The corpus is available in a preprocessed, formatting-normalized TMX format with paragraphs aligned across multiple languages. We describe the background to the corpus and its content, the process of its construction, and some of its interesting properties.",
|
| 26 |
-
author = "Alexandre Rafalovitch and Robert Dale",
|
| 27 |
-
year = "2009",
|
| 28 |
-
language = "English",
|
| 29 |
-
booktitle = "MT Summit XII proceedings",
|
| 30 |
-
publisher = "International Association of Machine Translation",
|
| 31 |
-
}"""
|
| 32 |
-
|
| 33 |
-
_HOMEPAGE = "http://opus.nlpl.eu/UN.php"
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
_LICENSE = ""
|
| 37 |
-
|
| 38 |
-
_VALID_LANGUAGE_PAIRS = {
|
| 39 |
-
("ar", "en"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/ar-en.txt.zip",
|
| 40 |
-
("ar", "es"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/ar-es.txt.zip",
|
| 41 |
-
("ar", "fr"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/ar-fr.txt.zip",
|
| 42 |
-
("ar", "ru"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/ar-ru.txt.zip",
|
| 43 |
-
("ar", "zh"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/ar-zh.txt.zip",
|
| 44 |
-
("en", "es"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/en-es.txt.zip",
|
| 45 |
-
("en", "fr"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/en-fr.txt.zip",
|
| 46 |
-
("en", "ru"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/en-ru.txt.zip",
|
| 47 |
-
("en", "zh"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/en-zh.txt.zip",
|
| 48 |
-
("es", "fr"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/es-fr.txt.zip",
|
| 49 |
-
("es", "ru"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/es-ru.txt.zip",
|
| 50 |
-
("es", "zh"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/es-zh.txt.zip",
|
| 51 |
-
("fr", "ru"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/fr-ru.txt.zip",
|
| 52 |
-
("fr", "zh"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/fr-zh.txt.zip",
|
| 53 |
-
("ru", "zh"): "http://opus.nlpl.eu/download.php?f=UN/v20090831/moses/ru-zh.txt.zip",
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
_VERSION = "2.0.0"
|
| 57 |
-
|
| 58 |
-
_DESCRIPTION = """\
|
| 59 |
-
United nations general assembly resolutions: A six-language parallel corpus.
|
| 60 |
-
This is a collection of translated documents from the United Nations originally compiled into a translation memory by Alexandre Rafalovitch, Robert Dale (see http://uncorpora.org).
|
| 61 |
-
6 languages, 15 bitexts
|
| 62 |
-
total number of files: 6
|
| 63 |
-
total number of tokens: 18.87M
|
| 64 |
-
total number of sentence fragments: 0.44M
|
| 65 |
-
"""
|
| 66 |
-
|
| 67 |
-
_BASE_NAME = "UN.{}-{}.{}"
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
class UnGaConfig(datasets.BuilderConfig):
|
| 71 |
-
"""BuilderConfig for United nations general assembly resolutions: A six-language parallel corpus"""
|
| 72 |
-
|
| 73 |
-
def __init__(self, language_pair=(None, None), **kwargs):
|
| 74 |
-
"""BuilderConfig for United nations general assembly resolutions: A six-language parallel corpus.
|
| 75 |
-
The first language in `language_pair` should consist of two strings joined by
|
| 76 |
-
an underscore (e.g. "en-tr").
|
| 77 |
-
Args:
|
| 78 |
-
language_pair: pair of languages that will be used for translation.
|
| 79 |
-
**kwargs: keyword arguments forwarded to super.
|
| 80 |
-
"""
|
| 81 |
-
name = "%s_to_%s" % (language_pair[0], language_pair[1])
|
| 82 |
-
|
| 83 |
-
description = ("Translation dataset from %s to %s or %s to %s.") % (
|
| 84 |
-
language_pair[0],
|
| 85 |
-
language_pair[1],
|
| 86 |
-
language_pair[1],
|
| 87 |
-
language_pair[0],
|
| 88 |
-
)
|
| 89 |
-
super(UnGaConfig, self).__init__(
|
| 90 |
-
name=name, description=description, version=datasets.Version(_VERSION, ""), **kwargs
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
# Validate language pair.
|
| 94 |
-
assert language_pair in _VALID_LANGUAGE_PAIRS, (
|
| 95 |
-
"Config language pair (%s, " "%s) not supported"
|
| 96 |
-
) % language_pair
|
| 97 |
-
|
| 98 |
-
self.language_pair = language_pair
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
class UnGa(datasets.GeneratorBasedBuilder):
|
| 102 |
-
|
| 103 |
-
BUILDER_CONFIGS = [
|
| 104 |
-
UnGaConfig(
|
| 105 |
-
language_pair=pair,
|
| 106 |
-
)
|
| 107 |
-
for pair in _VALID_LANGUAGE_PAIRS.keys()
|
| 108 |
-
]
|
| 109 |
-
|
| 110 |
-
BUILDER_CONFIG_CLASS = UnGaConfig
|
| 111 |
-
|
| 112 |
-
def _info(self):
|
| 113 |
-
return datasets.DatasetInfo(
|
| 114 |
-
description=_DESCRIPTION,
|
| 115 |
-
features=datasets.Features(
|
| 116 |
-
{
|
| 117 |
-
"id": datasets.Value("string"),
|
| 118 |
-
"translation": datasets.Translation(languages=tuple(self.config.language_pair)),
|
| 119 |
-
},
|
| 120 |
-
),
|
| 121 |
-
supervised_keys=None,
|
| 122 |
-
homepage=_HOMEPAGE,
|
| 123 |
-
citation=_CITATION,
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
def _split_generators(self, dl_manager):
|
| 127 |
-
download_url = _VALID_LANGUAGE_PAIRS.get(tuple(self.config.language_pair))
|
| 128 |
-
path = dl_manager.download_and_extract(download_url)
|
| 129 |
-
return [
|
| 130 |
-
datasets.SplitGenerator(
|
| 131 |
-
name=datasets.Split.TRAIN,
|
| 132 |
-
gen_kwargs={"datapath": path},
|
| 133 |
-
)
|
| 134 |
-
]
|
| 135 |
-
|
| 136 |
-
def _generate_examples(self, datapath):
|
| 137 |
-
lang1, lang2 = self.config.language_pair
|
| 138 |
-
lang1_file = _BASE_NAME.format(lang1, lang2, lang1)
|
| 139 |
-
lang2_file = _BASE_NAME.format(lang1, lang2, lang2)
|
| 140 |
-
lang1_path = os.path.join(datapath, lang1_file)
|
| 141 |
-
lang2_path = os.path.join(datapath, lang2_file)
|
| 142 |
-
|
| 143 |
-
with open(lang1_path, encoding="utf-8") as f1, open(lang2_path, encoding="utf-8") as f2:
|
| 144 |
-
for sentence_counter, (x, y) in enumerate(zip(f1, f2)):
|
| 145 |
-
x = x.strip()
|
| 146 |
-
y = y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