holylovenia commited on
Commit
79b1483
1 Parent(s): c3d4f67

Upload indo_religious_mt_en_id.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. indo_religious_mt_en_id.py +177 -0
indo_religious_mt_en_id.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+ import datasets
5
+
6
+ from nusacrowd.utils import schemas
7
+ from nusacrowd.utils.configs import NusantaraConfig
8
+ from nusacrowd.utils.constants import Tasks, DEFAULT_SOURCE_VIEW_NAME, DEFAULT_NUSANTARA_VIEW_NAME
9
+
10
+ _DATASETNAME = "indo_religious_mt_en_id"
11
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
12
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
13
+
14
+ _LANGUAGES = ["ind", "eng"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
15
+ _LOCAL = False
16
+ _CITATION = """\
17
+ @inproceedings{guntara-etal-2020-benchmarking,
18
+ title = "Benchmarking Multidomain {E}nglish-{I}ndonesian Machine Translation",
19
+ author = "Guntara, Tri Wahyu and
20
+ Aji, Alham Fikri and
21
+ Prasojo, Radityo Eko",
22
+ booktitle = "Proceedings of the 13th Workshop on Building and Using Comparable Corpora",
23
+ month = may,
24
+ year = "2020",
25
+ address = "Marseille, France",
26
+ publisher = "European Language Resources Association",
27
+ url = "https://aclanthology.org/2020.bucc-1.6",
28
+ pages = "35--43",
29
+ abstract = "In the context of Machine Translation (MT) from-and-to English, Bahasa Indonesia has been considered a low-resource language, and therefore applying Neural Machine Translation (NMT) which typically requires large training dataset proves to be problematic. In this paper, we show otherwise by collecting large, publicly-available datasets from the Web, which we split into several domains: news, religion, general, and conversation, to train and benchmark some variants of transformer-based NMT models across the domains. We show using BLEU that our models perform well across them , outperform the baseline Statistical Machine Translation (SMT) models, and perform comparably with Google Translate. Our datasets (with the standard split for training, validation, and testing), code, and models are available on https://github.com/gunnxx/indonesian-mt-data.",
30
+ language = "English",
31
+ ISBN = "979-10-95546-42-9",
32
+ }
33
+ """
34
+
35
+ _DESCRIPTION = """\
36
+ Indonesian Religious Domain MT En-Id consists of religious manuscripts or articles. These articles are different from news as they are not in a formal, informative style. Instead, they are written to advocate and inspire religious values, often times citing biblical or quranic anecdotes. An interesting property in the religion domain corpus is the localized names, for example, David to Daud, Mary to Maryam, Gabriel to Jibril, and more. In contrast, entity names are usually kept unchanged in other domains. We also find quite a handful of Indonesian translations of JW300 are missing the end sentence dot (.), even though the end sentence dot is present in their English counterpart. Some inconsistencies in the transliteration are also found, for example praying is sometimes written as \"salat\" or \"shalat\", or repentance as \"tobat\" or \"taubat\".
37
+ """
38
+
39
+ _HOMEPAGE = "https://github.com/gunnxx/indonesian-mt-data/tree/master/religious"
40
+
41
+ _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
42
+
43
+ _URLs = {
44
+ "test.en": "https://raw.githubusercontent.com/gunnxx/indonesian-mt-data/master/religious/test.en",
45
+ "test.id": "https://raw.githubusercontent.com/gunnxx/indonesian-mt-data/master/religious/test.id",
46
+ "valid.en": "https://raw.githubusercontent.com/gunnxx/indonesian-mt-data/master/religious/valid.en",
47
+ "valid.id": "https://raw.githubusercontent.com/gunnxx/indonesian-mt-data/master/religious/valid.id",
48
+ "train.en.0": "https://raw.githubusercontent.com/gunnxx/indonesian-mt-data/master/religious/train.en.0",
49
+ "train.en.1": "https://raw.githubusercontent.com/gunnxx/indonesian-mt-data/master/religious/train.en.1",
50
+ "train.id.0": "https://raw.githubusercontent.com/gunnxx/indonesian-mt-data/master/religious/train.id.0",
51
+ "train.id.1": "https://raw.githubusercontent.com/gunnxx/indonesian-mt-data/master/religious/train.id.1",
52
+ }
53
+
54
+ _SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]
55
+
56
+ _SOURCE_VERSION = "1.0.0"
57
+ _NUSANTARA_VERSION = "1.0.0"
58
+
59
+
60
+ class IndoReligiousMTEnId(datasets.GeneratorBasedBuilder):
61
+ """Indonesian Religious Domain MT En-Id is a machine translation dataset containing English-Indonesian parallel sentences collected from the religious manuscripts."""
62
+
63
+ BUILDER_CONFIGS = [
64
+ NusantaraConfig(
65
+ name="indo_religious_mt_en_id_source",
66
+ version=datasets.Version(_SOURCE_VERSION),
67
+ description="Bible En-Id source schema",
68
+ schema="source",
69
+ subset_id="indo_religious_mt_en_id",
70
+ ),
71
+ NusantaraConfig(
72
+ name="indo_religious_mt_en_id_nusantara_t2t",
73
+ version=datasets.Version(_NUSANTARA_VERSION),
74
+ description="Bible En-Id Nusantara schema",
75
+ schema="nusantara_t2t",
76
+ subset_id="indo_religious_mt_en_id",
77
+ ),
78
+ ]
79
+
80
+ DEFAULT_CONFIG_NAME = "indo_religious_mt_en_id_source"
81
+
82
+ def _info(self):
83
+ if self.config.schema == "source":
84
+ features = datasets.Features(
85
+ {
86
+ "text_1": datasets.Value("string"),
87
+ "text_2": datasets.Value("string"),
88
+ }
89
+ )
90
+ elif self.config.schema == "nusantara_t2t":
91
+ features = schemas.text2text_features
92
+
93
+ return datasets.DatasetInfo(
94
+ description=_DESCRIPTION,
95
+ features=features,
96
+ homepage=_HOMEPAGE,
97
+ license=_LICENSE,
98
+ citation=_CITATION,
99
+ )
100
+
101
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
102
+ data_files = {
103
+ "test.en": Path(dl_manager.download_and_extract(_URLs["test.en"])),
104
+ "test.id": Path(dl_manager.download_and_extract(_URLs["test.id"])),
105
+ "valid.en": Path(dl_manager.download_and_extract(_URLs["valid.en"])),
106
+ "valid.id": Path(dl_manager.download_and_extract(_URLs["valid.id"])),
107
+ "train.en.0": Path(dl_manager.download_and_extract(_URLs["train.en.0"])),
108
+ "train.en.1": Path(dl_manager.download_and_extract(_URLs["train.en.1"])),
109
+ "train.id.0": Path(dl_manager.download_and_extract(_URLs["train.id.0"])),
110
+ "train.id.1": Path(dl_manager.download_and_extract(_URLs["train.id.1"])),
111
+ }
112
+
113
+ return [
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.TEST,
116
+ gen_kwargs={
117
+ "filepath": {
118
+ "en": [data_files["test.en"]],
119
+ "id": [data_files["test.id"]],
120
+ }
121
+ },
122
+ ),
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.VALIDATION,
125
+ gen_kwargs={
126
+ "filepath": {
127
+ "en": [data_files["valid.en"]],
128
+ "id": [data_files["valid.id"]],
129
+ }
130
+ },
131
+ ),
132
+ datasets.SplitGenerator(
133
+ name=datasets.Split.TRAIN,
134
+ gen_kwargs={
135
+ "filepath": {
136
+ "en": [data_files["train.en.0"], data_files["train.en.1"]],
137
+ "id": [data_files["train.id.0"], data_files["train.id.1"]],
138
+ }
139
+ },
140
+ ),
141
+ ]
142
+
143
+ def _generate_examples(self, filepath: dict):
144
+
145
+ data_en = None
146
+ for file in filepath["en"]:
147
+ if data_en is None:
148
+ data_en = open(file, "r").readlines()
149
+ else:
150
+ data_en += open(file, "r").readlines()
151
+
152
+ data_id = None
153
+ for file in filepath["id"]:
154
+ if data_id is None:
155
+ data_id = open(file, "r").readlines()
156
+ else:
157
+ data_id += open(file, "r").readlines()
158
+
159
+ if self.config.schema == "source":
160
+ for id, (row_en, row_id) in enumerate(zip(data_en, data_id)):
161
+ ex = {
162
+ "text_1": row_en,
163
+ "text_2": row_id,
164
+ }
165
+ yield id, ex
166
+ elif self.config.schema == "nusantara_t2t":
167
+ for id, (row_en, row_id) in enumerate(zip(data_en, data_id)):
168
+ ex = {
169
+ "id": id,
170
+ "text_1": row_en,
171
+ "text_2": row_id,
172
+ "text_1_name": "eng",
173
+ "text_2_name": "ind",
174
+ }
175
+ yield id, ex
176
+ else:
177
+ raise ValueError(f"Invalid config: {self.config.name}")