holylovenia commited on
Commit
df7865a
·
1 Parent(s): 564be85

Upload bible_su_id.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. bible_su_id.py +136 -0
bible_su_id.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "bible_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{cahyawijaya-etal-2021-indonlg,
19
+ title = "{I}ndo{NLG}: Benchmark and Resources for Evaluating {I}ndonesian Natural Language Generation",
20
+ author = "Cahyawijaya, Samuel and
21
+ Winata, Genta Indra and
22
+ Wilie, Bryan and
23
+ Vincentio, Karissa and
24
+ Li, Xiaohong and
25
+ Kuncoro, Adhiguna and
26
+ Ruder, Sebastian and
27
+ Lim, Zhi Yuan and
28
+ Bahar, Syafri and
29
+ Khodra, Masayu and
30
+ Purwarianti, Ayu and
31
+ Fung, Pascale",
32
+ booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing",
33
+ month = nov,
34
+ year = "2021",
35
+ address = "Online and Punta Cana, Dominican Republic",
36
+ publisher = "Association for Computational Linguistics",
37
+ url = "https://aclanthology.org/2021.emnlp-main.699",
38
+ doi = "10.18653/v1/2021.emnlp-main.699",
39
+ pages = "8875--8898",
40
+ 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.",
41
+ }
42
+ """
43
+
44
+ _DESCRIPTION = """\
45
+ Bible Su-Id is a machine translation dataset containing Indonesian-Sundanese parallel sentences collected from the bible. As there is no existing parallel corpus for Sundanese and Indonesian, we create a new dataset for Sundanese and Indonesian translation generated from the Bible. We create a verse-aligned parallel corpus with a 75%, 10%, and 15% split for the training, validation, and test sets. The dataset is also evaluated in both directions.
46
+ """
47
+
48
+ _HOMEPAGE = "https://github.com/IndoNLP/indonlg"
49
+
50
+ _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
51
+
52
+ _URLs = {"indonlg": "https://storage.googleapis.com/babert-pretraining/IndoNLG_finals/downstream_task/downstream_task_datasets.zip"}
53
+
54
+ _SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]
55
+
56
+ _SOURCE_VERSION = "1.0.0"
57
+ _NUSANTARA_VERSION = "1.0.0"
58
+
59
+
60
+ class BibleSuId(datasets.GeneratorBasedBuilder):
61
+ """Bible Su-Id is a machine translation dataset containing Indonesian-Sundanese parallel sentences collected from the bible.."""
62
+
63
+ BUILDER_CONFIGS = [
64
+ NusantaraConfig(
65
+ name="bible_su_id_source",
66
+ version=datasets.Version(_SOURCE_VERSION),
67
+ description="Bible Su-Id source schema",
68
+ schema="source",
69
+ subset_id="bible_su_id",
70
+ ),
71
+ NusantaraConfig(
72
+ name="bible_su_id_nusantara_t2t",
73
+ version=datasets.Version(_NUSANTARA_VERSION),
74
+ description="Bible Su-Id Nusantara schema",
75
+ schema="nusantara_t2t",
76
+ subset_id="bible_su_id",
77
+ ),
78
+ ]
79
+
80
+ DEFAULT_CONFIG_NAME = "bible_su_id_source"
81
+
82
+ def _info(self):
83
+ if self.config.schema == "source":
84
+ features = datasets.Features({"id": datasets.Value("string"), "text": datasets.Value("string"), "label": datasets.Value("string")})
85
+ elif self.config.schema == "nusantara_t2t":
86
+ features = schemas.text2text_features
87
+
88
+ return datasets.DatasetInfo(
89
+ description=_DESCRIPTION,
90
+ features=features,
91
+ homepage=_HOMEPAGE,
92
+ license=_LICENSE,
93
+ citation=_CITATION,
94
+ )
95
+
96
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
97
+ base_path = Path(dl_manager.download_and_extract(_URLs["indonlg"])) / "IndoNLG_downstream_tasks" / "MT_SUNIBS_INZNTV"
98
+ data_files = {
99
+ "train": base_path / "train_preprocess.json",
100
+ "validation": base_path / "valid_preprocess.json",
101
+ "test": base_path / "test_preprocess.json",
102
+ }
103
+
104
+ return [
105
+ datasets.SplitGenerator(
106
+ name=datasets.Split.TRAIN,
107
+ gen_kwargs={"filepath": data_files["train"]},
108
+ ),
109
+ datasets.SplitGenerator(
110
+ name=datasets.Split.VALIDATION,
111
+ gen_kwargs={"filepath": data_files["validation"]},
112
+ ),
113
+ datasets.SplitGenerator(
114
+ name=datasets.Split.TEST,
115
+ gen_kwargs={"filepath": data_files["test"]},
116
+ ),
117
+ ]
118
+
119
+ def _generate_examples(self, filepath: Path):
120
+ data = json.load(open(filepath, "r"))
121
+ if self.config.schema == "source":
122
+ for row in data:
123
+ ex = {"id": row["id"], "text": row["text"], "label": row["label"]}
124
+ yield row["id"], ex
125
+ elif self.config.schema == "nusantara_t2t":
126
+ for row in data:
127
+ ex = {
128
+ "id": row["id"],
129
+ "text_1": row["text"],
130
+ "text_2": row["label"],
131
+ "text_1_name": "sun",
132
+ "text_2_name": "ind",
133
+ }
134
+ yield row["id"], ex
135
+ else:
136
+ raise ValueError(f"Invalid config: {self.config.name}")