Datasets:
Commit
•
d202709
1
Parent(s):
cee4f91
Delete loading script
Browse files- opus_wikipedia.py +0 -127
opus_wikipedia.py
DELETED
@@ -1,127 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 HuggingFace Datasets Authors.
|
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 |
-
# Lint as: python3
|
17 |
-
import os
|
18 |
-
|
19 |
-
import datasets
|
20 |
-
|
21 |
-
|
22 |
-
_DESCRIPTION = """\
|
23 |
-
This is a corpus of parallel sentences extracted from Wikipedia by Krzysztof Wołk and Krzysztof Marasek. Please cite the following publication if you use the data: Krzysztof Wołk and Krzysztof Marasek: Building Subject-aligned Comparable Corpora and Mining it for Truly Parallel Sentence Pairs., Procedia Technology, 18, Elsevier, p.126-132, 2014
|
24 |
-
20 languages, 36 bitexts
|
25 |
-
total number of files: 114
|
26 |
-
total number of tokens: 610.13M
|
27 |
-
total number of sentence fragments: 25.90M
|
28 |
-
"""
|
29 |
-
_HOMEPAGE_URL = "http://opus.nlpl.eu/Wikipedia.php"
|
30 |
-
_CITATION = """\
|
31 |
-
@InProceedings{TIEDEMANN12.463,
|
32 |
-
author = {J{\"o}rg Tiedemann},
|
33 |
-
title = {Parallel Data, Tools and Interfaces in OPUS},
|
34 |
-
booktitle = {Proceedings of the Eight International Conference on Language Resources and Evaluation (LREC'12)},
|
35 |
-
year = {2012},
|
36 |
-
month = {may},
|
37 |
-
date = {23-25},
|
38 |
-
address = {Istanbul, Turkey},
|
39 |
-
editor = {Nicoletta Calzolari (Conference Chair) and Khalid Choukri and Thierry Declerck and Mehmet Ugur Dogan and Bente Maegaard and Joseph Mariani and Jan Odijk and Stelios Piperidis},
|
40 |
-
publisher = {European Language Resources Association (ELRA)},
|
41 |
-
isbn = {978-2-9517408-7-7},
|
42 |
-
language = {english}
|
43 |
-
}
|
44 |
-
"""
|
45 |
-
|
46 |
-
_VERSION = "1.0.0"
|
47 |
-
_BASE_NAME = "Wikipedia.{}.{}"
|
48 |
-
_BASE_URL = "https://object.pouta.csc.fi/OPUS-Wikipedia/v1.0/moses/{}-{}.txt.zip"
|
49 |
-
# Please note that only few pairs are shown here. You can use config to generate data for all language pairs
|
50 |
-
_LANGUAGE_PAIRS = [
|
51 |
-
("ar", "en"),
|
52 |
-
("ar", "pl"),
|
53 |
-
("en", "sl"),
|
54 |
-
("en", "ru"),
|
55 |
-
("en", "vi"),
|
56 |
-
]
|
57 |
-
|
58 |
-
|
59 |
-
class WikipediaConfig(datasets.BuilderConfig):
|
60 |
-
def __init__(self, *args, lang1=None, lang2=None, **kwargs):
|
61 |
-
super().__init__(
|
62 |
-
*args,
|
63 |
-
name=f"{lang1}-{lang2}",
|
64 |
-
**kwargs,
|
65 |
-
)
|
66 |
-
self.lang1 = lang1
|
67 |
-
self.lang2 = lang2
|
68 |
-
|
69 |
-
|
70 |
-
class OpusWikipedia(datasets.GeneratorBasedBuilder):
|
71 |
-
BUILDER_CONFIGS = [
|
72 |
-
WikipediaConfig(
|
73 |
-
lang1=lang1,
|
74 |
-
lang2=lang2,
|
75 |
-
description=f"Translating {lang1} to {lang2} or vice versa",
|
76 |
-
version=datasets.Version(_VERSION),
|
77 |
-
)
|
78 |
-
for lang1, lang2 in _LANGUAGE_PAIRS
|
79 |
-
]
|
80 |
-
BUILDER_CONFIG_CLASS = WikipediaConfig
|
81 |
-
|
82 |
-
def _info(self):
|
83 |
-
return datasets.DatasetInfo(
|
84 |
-
description=_DESCRIPTION,
|
85 |
-
features=datasets.Features(
|
86 |
-
{
|
87 |
-
"id": datasets.Value("string"),
|
88 |
-
"translation": datasets.Translation(languages=(self.config.lang1, self.config.lang2)),
|
89 |
-
},
|
90 |
-
),
|
91 |
-
supervised_keys=None,
|
92 |
-
homepage=_HOMEPAGE_URL,
|
93 |
-
citation=_CITATION,
|
94 |
-
)
|
95 |
-
|
96 |
-
def _split_generators(self, dl_manager):
|
97 |
-
def _base_url(lang1, lang2):
|
98 |
-
return _BASE_URL.format(lang1, lang2)
|
99 |
-
|
100 |
-
download_url = _base_url(self.config.lang1, self.config.lang2)
|
101 |
-
path = dl_manager.download_and_extract(download_url)
|
102 |
-
return [
|
103 |
-
datasets.SplitGenerator(
|
104 |
-
name=datasets.Split.TRAIN,
|
105 |
-
gen_kwargs={"datapath": path},
|
106 |
-
)
|
107 |
-
]
|
108 |
-
|
109 |
-
def _generate_examples(self, datapath):
|
110 |
-
l1, l2 = self.config.lang1, self.config.lang2
|
111 |
-
folder = l1 + "-" + l2
|
112 |
-
l1_file = _BASE_NAME.format(folder, l1)
|
113 |
-
l2_file = _BASE_NAME.format(folder, l2)
|
114 |
-
l1_path = os.path.join(datapath, l1_file)
|
115 |
-
l2_path = os.path.join(datapath, l2_file)
|
116 |
-
with open(l1_path, encoding="utf-8") as f1, open(l2_path, encoding="utf-8") as f2:
|
117 |
-
for sentence_counter, (x, y) in enumerate(zip(f1, f2)):
|
118 |
-
x = x.strip()
|
119 |
-
y = y.strip()
|
120 |
-
result = (
|
121 |
-
sentence_counter,
|
122 |
-
{
|
123 |
-
"id": str(sentence_counter),
|
124 |
-
"translation": {l1: x, l2: y},
|
125 |
-
},
|
126 |
-
)
|
127 |
-
yield result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|