holylovenia commited on
Commit
a49e8ce
1 Parent(s): 2082237

Upload stif_indonesia.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. stif_indonesia.py +141 -0
stif_indonesia.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "stif_indonesia"
11
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
12
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
13
+
14
+ _LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
15
+ _LOCAL = False
16
+ _CITATION = """\
17
+ @inproceedings{wibowo2020semi,
18
+ title={Semi-supervised low-resource style transfer of indonesian informal to formal language with iterative forward-translation},
19
+ author={Wibowo, Haryo Akbarianto and Prawiro, Tatag Aziz and Ihsan, Muhammad and Aji, Alham Fikri and Prasojo, Radityo Eko and Mahendra, Rahmad and Fitriany, Suci},
20
+ booktitle={2020 International Conference on Asian Language Processing (IALP)},
21
+ pages={310--315},
22
+ year={2020},
23
+ organization={IEEE}
24
+ }
25
+ """
26
+
27
+ _DESCRIPTION = """\
28
+ STIF-Indonesia is formal-informal (bahasa baku - bahasa alay/slang) style transfer for Indonesian. Texts were collected from Twitter. Then, native speakers were aksed to transform the text into formal style.
29
+ """
30
+
31
+ _HOMEPAGE = "https://github.com/haryoa/stif-indonesia"
32
+
33
+ _LICENSE = "MIT"
34
+
35
+ _BASEURL = "https://raw.githubusercontent.com/haryoa/stif-indonesia/main/data/labelled/"
36
+ _URLs = {
37
+ "dev.for": _BASEURL + "dev.for",
38
+ "dev.inf": _BASEURL + "dev.inf",
39
+ "test.for": _BASEURL + "test.for",
40
+ "test.inf": _BASEURL + "test.inf",
41
+ "train.for": _BASEURL + "train.for",
42
+ "train.inf": _BASEURL + "train.inf",
43
+ }
44
+
45
+ _SUPPORTED_TASKS = [Tasks.PARAPHRASING]
46
+
47
+ _SOURCE_VERSION = "1.0.0"
48
+ _NUSANTARA_VERSION = "1.0.0"
49
+
50
+
51
+ class STIFIndonesia(datasets.GeneratorBasedBuilder):
52
+ """STIF-Indonesia is formal-informal/colloquial style transfer for Indonesian."""
53
+
54
+ BUILDER_CONFIGS = [
55
+ NusantaraConfig(
56
+ name="stif_indonesia_source",
57
+ version=datasets.Version(_SOURCE_VERSION),
58
+ description="STIF Indonesia source schema",
59
+ schema="source",
60
+ subset_id="stif_indonesia",
61
+ ),
62
+ NusantaraConfig(
63
+ name="stif_indonesia_nusantara_t2t",
64
+ version=datasets.Version(_NUSANTARA_VERSION),
65
+ description="STIF Indonesia Nusantara schema",
66
+ schema="nusantara_t2t",
67
+ subset_id="stif_indonesia",
68
+ ),
69
+ ]
70
+
71
+ DEFAULT_CONFIG_NAME = "stif_indonesia_source"
72
+
73
+ def _info(self):
74
+ if self.config.schema == "source":
75
+ features = datasets.Features({"id": datasets.Value("string"), "formal": datasets.Value("string"), "informal": datasets.Value("string")})
76
+ elif self.config.schema == "nusantara_t2t":
77
+ features = schemas.text2text_features
78
+
79
+ return datasets.DatasetInfo(
80
+ description=_DESCRIPTION,
81
+ features=features,
82
+ homepage=_HOMEPAGE,
83
+ license=_LICENSE,
84
+ citation=_CITATION,
85
+ )
86
+
87
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
88
+ data_files = {}
89
+ for key in _URLs:
90
+ data_files[key] = Path(dl_manager.download_and_extract(_URLs[key]))
91
+
92
+ return [
93
+ datasets.SplitGenerator(
94
+ name=datasets.Split.TEST,
95
+ gen_kwargs={
96
+ "filepath": {
97
+ "formal": data_files["test.for"],
98
+ "informal": data_files["test.inf"],
99
+ }
100
+ },
101
+ ),
102
+ datasets.SplitGenerator(
103
+ name=datasets.Split.VALIDATION,
104
+ gen_kwargs={
105
+ "filepath": {
106
+ "formal": data_files["dev.for"],
107
+ "informal": data_files["dev.inf"],
108
+ }
109
+ },
110
+ ),
111
+ datasets.SplitGenerator(
112
+ name=datasets.Split.TRAIN,
113
+ gen_kwargs={
114
+ "filepath": {
115
+ "formal": data_files["train.for"],
116
+ "informal": data_files["train.inf"],
117
+ }
118
+ },
119
+ ),
120
+ ]
121
+
122
+ def _generate_examples(self, filepath: Path):
123
+ data_for = open(filepath["formal"], "r").readlines()
124
+ data_inf = open(filepath["informal"], "r").readlines()
125
+
126
+ if self.config.schema == "source":
127
+ for id, (row_for, row_inf) in enumerate(zip(data_for, data_inf)):
128
+ ex = {"id": id, "formal": row_for.strip(), "informal": row_inf.strip()}
129
+ yield id, ex
130
+ elif self.config.schema == "nusantara_t2t":
131
+ for id, (row_for, row_inf) in enumerate(zip(data_for, data_inf)):
132
+ ex = {
133
+ "id": id,
134
+ "text_1": row_for.strip(),
135
+ "text_2": row_inf.strip(),
136
+ "text_1_name": "formal",
137
+ "text_2_name": "informal",
138
+ }
139
+ yield id, ex
140
+ else:
141
+ raise ValueError(f"Invalid config: {self.config.name}")