holylovenia commited on
Commit
f54a09b
1 Parent(s): 875b9c1

Upload parallel_su_id.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. parallel_su_id.py +123 -0
parallel_su_id.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+ import datasets
5
+ import json
6
+
7
+ from nusacrowd.utils import schemas
8
+ from nusacrowd.utils.configs import NusantaraConfig
9
+ from nusacrowd.utils.constants import Tasks, DEFAULT_SOURCE_VIEW_NAME, DEFAULT_NUSANTARA_VIEW_NAME
10
+
11
+ _DATASETNAME = "parallel_su_id"
12
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
13
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
14
+
15
+ _LANGUAGES = ["ind", "sun"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
16
+ _LOCAL = False
17
+ _CITATION = """\
18
+ @INPROCEEDINGS{7437678,
19
+ author={Suryani, Arie Ardiyanti and Widyantoro, Dwi Hendratmo and Purwarianti, Ayu and Sudaryat, Yayat},
20
+ booktitle={2015 International Conference on Information Technology Systems and Innovation (ICITSI)},
21
+ title={Experiment on a phrase-based statistical machine translation using PoS Tag information for Sundanese into Indonesian},
22
+ year={2015},
23
+ volume={},
24
+ number={},
25
+ pages={1-6},
26
+ doi={10.1109/ICITSI.2015.7437678}}
27
+ """
28
+
29
+ _DESCRIPTION = """\
30
+ This data contains 3616 lines of Sundanese sentences taken from the online Sundanese language magazine Mangle, West Java Dakwah Council, and Balebat, and translated into Indonesian by several students of the Sundanese language study program UPI Bandung.
31
+ """
32
+
33
+ _HOMEPAGE = "https://dataverse.telkomuniversity.ac.id/dataset.xhtml?persistentId=doi:10.34820/FK2/HDYWXW"
34
+
35
+ _LICENSE = "Creative Commons CC0 - No Rights Reserved"
36
+
37
+ _URLs = {"ind": "https://dataverse.telkomuniversity.ac.id/api/access/datafile/:persistentId?persistentId=doi:10.34820/FK2/HDYWXW/032QZD",
38
+ "sun": "https://dataverse.telkomuniversity.ac.id/api/access/datafile/:persistentId?persistentId=doi:10.34820/FK2/HDYWXW/IVP3G5"}
39
+
40
+ _SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]
41
+
42
+ _SOURCE_VERSION = "1.0.0"
43
+ _NUSANTARA_VERSION = "1.0.0"
44
+
45
+
46
+ class ParallelSuId(datasets.GeneratorBasedBuilder):
47
+ """Parallel Su-Id is a machine translation dataset containing Indonesian-Sundanese parallel sentences collected from the online Sundanese language magazine Mangle, West Java Dakwah Council, and Balebat."""
48
+
49
+ BUILDER_CONFIGS = [
50
+ NusantaraConfig(
51
+ name="parallel_su_id_source",
52
+ version=datasets.Version(_SOURCE_VERSION),
53
+ description="Parallel Su-Id source schema",
54
+ schema="source",
55
+ subset_id="parallel_su_id",
56
+ ),
57
+ NusantaraConfig(
58
+ name="parallel_su_id_nusantara_t2t",
59
+ version=datasets.Version(_NUSANTARA_VERSION),
60
+ description="Parallel Su-Id Nusantara schema",
61
+ schema="nusantara_t2t",
62
+ subset_id="parallel_su_id",
63
+ ),
64
+ ]
65
+
66
+ DEFAULT_CONFIG_NAME = "parallel_su_id_source"
67
+
68
+ def _info(self):
69
+ if self.config.schema == "source":
70
+ features = datasets.Features({"id": datasets.Value("string"), "text": datasets.Value("string"), "label": datasets.Value("string")})
71
+ elif self.config.schema == "nusantara_t2t":
72
+ features = schemas.text2text_features
73
+
74
+ return datasets.DatasetInfo(
75
+ description=_DESCRIPTION,
76
+ features=features,
77
+ homepage=_HOMEPAGE,
78
+ license=_LICENSE,
79
+ citation=_CITATION,
80
+ )
81
+
82
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
83
+ ind_path = Path(dl_manager.download_and_extract(_URLs["ind"]))
84
+ sun_path = Path(dl_manager.download_and_extract(_URLs["sun"]))
85
+ data_files = {
86
+ "ind": ind_path,
87
+ "sun": sun_path,
88
+ }
89
+
90
+ return [
91
+ datasets.SplitGenerator(
92
+ name=datasets.Split.TRAIN,
93
+ gen_kwargs={"filepath_dict": data_files},
94
+ )
95
+ ]
96
+
97
+ def _generate_examples(self, filepath_dict):
98
+ data = {}
99
+ for lang, path in filepath_dict.items():
100
+ file = open(path, "r")
101
+ data[lang] = []
102
+ for line in file:
103
+ data[lang].append(line)
104
+ if self.config.schema == "source":
105
+ for i in range(len(data[lang])):
106
+ ex = {
107
+ "id": i,
108
+ "text": data['sun'][i].replace("\n",""),
109
+ "label": data['ind'][i].replace("\n","")
110
+ }
111
+ yield i, ex
112
+ elif self.config.schema == "nusantara_t2t":
113
+ for i in range(len(data[lang])):
114
+ ex = {
115
+ "id": i,
116
+ "text_1": data['sun'][i].replace("\n",""),
117
+ "text_2": data['ind'][i].replace("\n",""),
118
+ "text_1_name": "sun",
119
+ "text_2_name": "ind",
120
+ }
121
+ yield i, ex
122
+ else:
123
+ raise ValueError(f"Invalid config: {self.config.name}")