holylovenia commited on
Commit
154c66a
·
1 Parent(s): 1970eb6

Upload parallel_id_nyo.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. parallel_id_nyo.py +164 -0
parallel_id_nyo.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+ import datasets
5
+ import pandas as pd
6
+
7
+ from nusacrowd.utils import schemas
8
+ from nusacrowd.utils.configs import NusantaraConfig
9
+ from nusacrowd.utils.constants import (
10
+ DEFAULT_NUSANTARA_VIEW_NAME,
11
+ DEFAULT_SOURCE_VIEW_NAME,
12
+ Tasks,
13
+ )
14
+
15
+ _DATASETNAME = "parallel_id_nyo"
16
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
17
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
18
+
19
+ _LOCAL = False
20
+ _LANGUAGES = ["ind", "abl"]
21
+
22
+ _CITATION = """\
23
+ @article{Abidin_2021,
24
+ doi = {10.1088/1742-6596/1751/1/012036},
25
+ url = {https://dx.doi.org/10.1088/1742-6596/1751/1/012036},
26
+ year = {2021},
27
+ month = {jan},
28
+ publisher = {IOP Publishing},
29
+ volume = {1751},
30
+ number = {1},
31
+ pages = {012036},
32
+ author = {Z Abidin and Permata and I Ahmad and Rusliyawati},
33
+ title = {Effect of mono corpus quantity on statistical machine translation
34
+ Indonesian - Lampung dialect of nyo},
35
+ journal = {Journal of Physics: Conference Series},
36
+ abstract = {Lampung Province is located on the island of Sumatera. For the
37
+ immigrants in Lampung, they have difficulty in
38
+ communicating with the indigenous people of Lampung. As an alternative, both
39
+ immigrants and the indigenous people of Lampung speak Indonesian.
40
+ This research aims to build a language model from Indonesian language and a
41
+ translation model from the Lampung language dialect of nyo, both models will
42
+ be combined in a Moses decoder.
43
+ This research focuses on observing the effect of adding mono corpus to the
44
+ experimental statistical machine translation of
45
+ Indonesian - Lampung dialect of nyo.
46
+ This research uses 3000 pair parallel corpus in Indonesia language and
47
+ Lampung language dialect of nyo as source language
48
+ and uses 3000 mono corpus sentences in Lampung language
49
+ dialect of nyo as target language. The results showed that the accuracy
50
+ value in bilingual evalution under-study score when using 1000 sentences,
51
+ 2000 sentences, 3000 sentences mono corpus
52
+ show the accuracy value of the bilingual evaluation under-study,
53
+ respectively, namely 40.97 %, 41.80 % and 45.26 %.}
54
+ }
55
+ """
56
+
57
+ _DESCRIPTION = """\
58
+ Dataset that contains Indonesian - Lampung language pairs.
59
+
60
+ The original data should contains 3000 rows, unfortunately,
61
+ not all of the instances in the original data is aligned perfectly.
62
+ Thus, this data only have the aligned ones, which only contain 1727 pairs.
63
+ """
64
+
65
+ _HOMEPAGE = "https://drive.google.com/drive/folders/1oNpybrq5OJ_4Ne0HS5w9eHqnZlZASpmC?usp=sharing"
66
+
67
+ _LICENSE = "Unknown"
68
+
69
+ # WARNING: Incomplete data!
70
+ _URLs = {
71
+ "train": "https://raw.githubusercontent.com/haryoa/IndoData/main/data_ind_lampung_1729_line.csv"
72
+ }
73
+
74
+ _SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]
75
+
76
+ _SOURCE_VERSION = "1.0.0"
77
+ _NUSANTARA_VERSION = "1.0.0"
78
+
79
+ COL_INDONESIA = "indo"
80
+ COL_LAMPUNG = "lampung"
81
+
82
+
83
+ class ParallelIdNyo(datasets.GeneratorBasedBuilder):
84
+ """Dataset that contains Indonesian - Lampung language pairs."""
85
+
86
+ BUILDER_CONFIGS = [
87
+ NusantaraConfig(
88
+ name="parallel_id_nyo_source",
89
+ version=datasets.Version(_SOURCE_VERSION),
90
+ description="Parallel Id-Nyo source schema",
91
+ schema="source",
92
+ subset_id="parallel_id_nyo",
93
+ ),
94
+ NusantaraConfig(
95
+ name="parallel_id_nyo_nusantara_t2t",
96
+ version=datasets.Version(_NUSANTARA_VERSION),
97
+ description="Parallel Id-Nyo Nusantara schema",
98
+ schema="nusantara_t2t",
99
+ subset_id="parallel_id_nyo",
100
+ ),
101
+ ]
102
+
103
+ DEFAULT_CONFIG_NAME = "ted_en_id_source"
104
+
105
+ def _info(self):
106
+ if self.config.schema == "source":
107
+ features = datasets.Features(
108
+ {
109
+ "id": datasets.Value("string"),
110
+ "text": datasets.Value("string"),
111
+ "label": datasets.Value("string"),
112
+ }
113
+ )
114
+ elif self.config.schema == "nusantara_t2t":
115
+ features = schemas.text2text_features
116
+
117
+ return datasets.DatasetInfo(
118
+ description=_DESCRIPTION,
119
+ features=features,
120
+ homepage=_HOMEPAGE,
121
+ license=_LICENSE,
122
+ citation=_CITATION,
123
+ )
124
+
125
+ def _split_generators(
126
+ self, dl_manager: datasets.DownloadManager
127
+ ) -> List[datasets.SplitGenerator]:
128
+ path = Path(dl_manager.download_and_extract(_URLs["train"]))
129
+
130
+ return [
131
+ datasets.SplitGenerator(
132
+ name=datasets.Split.TRAIN,
133
+ gen_kwargs={"filepath": path},
134
+ )
135
+ ]
136
+
137
+ def _generate_examples(self, filepath: Path):
138
+
139
+ df = pd.read_csv(filepath).reset_index()
140
+
141
+ if self.config.schema == "source":
142
+ for idx, row in df.iterrows():
143
+ ex = {
144
+ "id": str(idx),
145
+ "text": str(row[COL_INDONESIA]).rstrip(),
146
+ "label": str(row[COL_LAMPUNG]).rstrip(),
147
+ }
148
+ yield idx, ex
149
+ elif self.config.schema == "nusantara_t2t":
150
+ for idx, row in df.iterrows():
151
+ ex = {
152
+ "id": str(idx),
153
+ "text_1": str(row[COL_INDONESIA]).rstrip(),
154
+ "text_2": str(row[COL_LAMPUNG]).rstrip(),
155
+ "text_1_name": "ind",
156
+ "text_2_name": "abl", # code name for lampung Nyo
157
+ }
158
+ yield idx, ex
159
+ else:
160
+ raise ValueError(f"Invalid config: {self.config.name}")
161
+
162
+
163
+ if __name__ == "__main__":
164
+ datasets.load_dataset(__file__)