holylovenia commited on
Commit
c0ff1df
1 Parent(s): 22e6f37

Upload bible_jv_id.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. bible_jv_id.py +151 -0
bible_jv_id.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+ import datasets
5
+ import json
6
+ import pandas as pd
7
+
8
+ from nusacrowd.utils import schemas
9
+ from nusacrowd.utils.configs import NusantaraConfig
10
+ from nusacrowd.utils.constants import Tasks, DEFAULT_SOURCE_VIEW_NAME, DEFAULT_NUSANTARA_VIEW_NAME
11
+
12
+ _DATASETNAME = "bible_jv_id"
13
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
14
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
15
+
16
+ _LANGUAGES = ["ind", "jav"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
17
+ _LOCAL = False
18
+ _CITATION = """\
19
+ @inproceedings{cahyawijaya-etal-2021-indonlg,
20
+ title = "{I}ndo{NLG}: Benchmark and Resources for Evaluating {I}ndonesian Natural Language Generation",
21
+ author = "Cahyawijaya, Samuel and
22
+ Winata, Genta Indra and
23
+ Wilie, Bryan and
24
+ Vincentio, Karissa and
25
+ Li, Xiaohong and
26
+ Kuncoro, Adhiguna and
27
+ Ruder, Sebastian and
28
+ Lim, Zhi Yuan and
29
+ Bahar, Syafri and
30
+ Khodra, Masayu and
31
+ Purwarianti, Ayu and
32
+ Fung, Pascale",
33
+ booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing",
34
+ month = nov,
35
+ year = "2021",
36
+ address = "Online and Punta Cana, Dominican Republic",
37
+ publisher = "Association for Computational Linguistics",
38
+ url = "https://aclanthology.org/2021.emnlp-main.699",
39
+ doi = "10.18653/v1/2021.emnlp-main.699",
40
+ pages = "8875--8898",
41
+ abstract = "Natural language generation (NLG) benchmarks provide an important avenue to measure progress and develop better NLG systems. Unfortunately, the lack of publicly available NLG benchmarks for low-resource languages poses a challenging barrier for building NLG systems that work well for languages with limited amounts of data. Here we introduce IndoNLG, the first benchmark to measure natural language generation (NLG) progress in three low-resource{---}yet widely spoken{---}languages of Indonesia: Indonesian, Javanese, and Sundanese. Altogether, these languages are spoken by more than 100 million native speakers, and hence constitute an important use case of NLG systems today. Concretely, IndoNLG covers six tasks: summarization, question answering, chit-chat, and three different pairs of machine translation (MT) tasks. We collate a clean pretraining corpus of Indonesian, Sundanese, and Javanese datasets, Indo4B-Plus, which is used to pretrain our models: IndoBART and IndoGPT. We show that IndoBART and IndoGPT achieve competitive performance on all tasks{---}despite using only one-fifth the parameters of a larger multilingual model, mBART-large (Liu et al., 2020). This finding emphasizes the importance of pretraining on closely related, localized languages to achieve more efficient learning and faster inference at very low-resource languages like Javanese and Sundanese.",
42
+ }
43
+ """
44
+
45
+ _DESCRIPTION = """\
46
+ Analogous to the En ↔ Id and Su ↔ Id datasets, we create a new dataset for Javanese and Indonesian translation generated from the verse-aligned Bible parallel corpus with the same split setting. In terms of size, both the Su ↔ Id and Jv ↔ Id datasets are much smaller compared to the En ↔ Id dataset, because there are Bible chapters for which translations are available for Indonesian, albeit not for the local languages."""
47
+
48
+ _HOMEPAGE = "https://github.com/IndoNLP/indonlg"
49
+
50
+ _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
51
+
52
+ _URLs = {
53
+ "indonlg": "https://storage.googleapis.com/babert-pretraining/IndoNLG_finals/downstream_task/downstream_task_datasets.zip"
54
+ }
55
+
56
+ _SUPPORTED_TASKS = [
57
+ Tasks.MACHINE_TRANSLATION
58
+ ]
59
+
60
+ _SOURCE_VERSION = "1.0.0"
61
+ _NUSANTARA_VERSION = "1.0.0"
62
+
63
+ class BibleEnId(datasets.GeneratorBasedBuilder):
64
+ """Bible Jv-Id is a machine translation dataset containing Indonesian-Javanese parallel sentences collected from the bible.."""
65
+
66
+ BUILDER_CONFIGS = [
67
+ NusantaraConfig(
68
+ name="bible_jv_id_source",
69
+ version=datasets.Version(_SOURCE_VERSION),
70
+ description="Bible Jv-Id source schema",
71
+ schema="source",
72
+ subset_id="bible_jv_id",
73
+ ),
74
+ NusantaraConfig(
75
+ name="bible_jv_id_nusantara_t2t",
76
+ version=datasets.Version(_NUSANTARA_VERSION),
77
+ description="Bible Jv-Id Nusantara schema",
78
+ schema="nusantara_t2t",
79
+ subset_id="bible_jv_id",
80
+ )
81
+ ]
82
+
83
+ DEFAULT_CONFIG_NAME = "bible_jv_id_source"
84
+
85
+ def _info(self):
86
+ if self.config.schema == "source":
87
+ features = datasets.Features(
88
+ {
89
+ "id": datasets.Value("string"),
90
+ "text": datasets.Value("string"),
91
+ "label": datasets.Value("string")
92
+ }
93
+ )
94
+ elif self.config.schema == "nusantara_t2t":
95
+ features = schemas.text2text_features
96
+
97
+ return datasets.DatasetInfo(
98
+ description=_DESCRIPTION,
99
+ features=features,
100
+ homepage=_HOMEPAGE,
101
+ license=_LICENSE,
102
+ citation=_CITATION,
103
+ )
104
+
105
+ def _split_generators(
106
+ self, dl_manager: datasets.DownloadManager
107
+ ) -> List[datasets.SplitGenerator]:
108
+ base_path = Path(dl_manager.download_and_extract(_URLs['indonlg'])) / 'IndoNLG_downstream_tasks' / 'MT_JAVNRF_INZNTV'
109
+ data_files = {
110
+ "train": base_path / 'train_preprocess.json',
111
+ "validation": base_path / 'valid_preprocess.json',
112
+ "test": base_path / 'test_preprocess.json',
113
+ }
114
+
115
+ return [
116
+ datasets.SplitGenerator(
117
+ name=datasets.Split.TRAIN,
118
+ gen_kwargs={"filepath": data_files["train"]},
119
+ ),
120
+ datasets.SplitGenerator(
121
+ name=datasets.Split.VALIDATION,
122
+ gen_kwargs={"filepath": data_files["validation"]},
123
+ ),
124
+ datasets.SplitGenerator(
125
+ name=datasets.Split.TEST,
126
+ gen_kwargs={"filepath": data_files["test"]},
127
+ ),
128
+ ]
129
+
130
+ def _generate_examples(self, filepath: Path):
131
+ data = json.load(open(filepath, 'r'))
132
+ if self.config.schema == "source":
133
+ for row in data:
134
+ ex = {
135
+ "id": row['id'],
136
+ "text": row['text'],
137
+ "label": row['label']
138
+ }
139
+ yield row['id'], ex
140
+ elif self.config.schema == "nusantara_t2t":
141
+ for row in data:
142
+ ex = {
143
+ "id": row['id'],
144
+ "text_1": row['text'],
145
+ "text_2": row['label'],
146
+ "text_1_name": 'jav',
147
+ "text_2_name": 'ind',
148
+ }
149
+ yield row['id'], ex
150
+ else:
151
+ raise ValueError(f"Invalid config: {self.config.name}")