holylovenia commited on
Commit
8ca8b46
1 Parent(s): bfb8def

Upload ted_en_id.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. ted_en_id.py +149 -0
ted_en_id.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from pathlib import Path
3
+ from typing import List
4
+
5
+ import datasets
6
+
7
+ from nusacrowd.utils import schemas
8
+ from nusacrowd.utils.configs import NusantaraConfig
9
+ from nusacrowd.utils.constants import (DEFAULT_NUSANTARA_VIEW_NAME,
10
+ DEFAULT_SOURCE_VIEW_NAME, Tasks)
11
+
12
+ _DATASETNAME = "ted_en_id"
13
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
14
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
15
+
16
+ _LANGUAGES = ["ind", "eng"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
17
+ _LOCAL = False
18
+ _CITATION = """\
19
+ @inproceedings{qi2018and,
20
+ title={When and Why Are Pre-Trained Word Embeddings Useful for Neural Machine Translation?},
21
+ author={Qi, Ye and Sachan, Devendra and Felix, Matthieu and Padmanabhan, Sarguna and Neubig, Graham},
22
+ booktitle={Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers)},
23
+ pages={529--535},
24
+ year={2018}
25
+ }
26
+
27
+ @inproceedings{cahyawijaya-etal-2021-indonlg,
28
+ title = "{I}ndo{NLG}: Benchmark and Resources for Evaluating {I}ndonesian Natural Language Generation",
29
+ author = "Cahyawijaya, Samuel and
30
+ Winata, Genta Indra and
31
+ Wilie, Bryan and
32
+ Vincentio, Karissa and
33
+ Li, Xiaohong and
34
+ Kuncoro, Adhiguna and
35
+ Ruder, Sebastian and
36
+ Lim, Zhi Yuan and
37
+ Bahar, Syafri and
38
+ Khodra, Masayu and
39
+ Purwarianti, Ayu and
40
+ Fung, Pascale",
41
+ booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing",
42
+ month = nov,
43
+ year = "2021",
44
+ address = "Online and Punta Cana, Dominican Republic",
45
+ publisher = "Association for Computational Linguistics",
46
+ url = "https://aclanthology.org/2021.emnlp-main.699",
47
+ doi = "10.18653/v1/2021.emnlp-main.699",
48
+ pages = "8875--8898",
49
+ 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.",
50
+ }
51
+ """
52
+
53
+ _DESCRIPTION = """\
54
+ TED En-Id is a machine translation dataset containing Indonesian-English parallel sentences collected from the TED talk transcripts. We split the dataset and use 75% as the training set, 10% as the validation set, and 15% as the test set. Each of the datasets is evaluated in both directions, i.e., English to Indonesian (En → Id) and Indonesian to English (Id → En) translations.
55
+ """
56
+
57
+ _HOMEPAGE = "https://github.com/IndoNLP/indonlg"
58
+
59
+ _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
60
+
61
+ _URLs = {"indonlg": "https://storage.googleapis.com/babert-pretraining/IndoNLG_finals/downstream_task/downstream_task_datasets.zip"}
62
+
63
+ _SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]
64
+
65
+ _SOURCE_VERSION = "1.0.0"
66
+ _NUSANTARA_VERSION = "1.0.0"
67
+
68
+
69
+ class TEDEnId(datasets.GeneratorBasedBuilder):
70
+ """TED En-Id is a machine translation dataset containing Indonesian-English parallel sentences collected from the TED talk transcripts."""
71
+
72
+ BUILDER_CONFIGS = [
73
+ NusantaraConfig(
74
+ name="ted_en_id_source",
75
+ version=datasets.Version(_SOURCE_VERSION),
76
+ description="TED En-Id source schema",
77
+ schema="source",
78
+ subset_id="ted_en_id",
79
+ ),
80
+ NusantaraConfig(
81
+ name="ted_en_id_nusantara_t2t",
82
+ version=datasets.Version(_NUSANTARA_VERSION),
83
+ description="TED En-Id Nusantara schema",
84
+ schema="nusantara_t2t",
85
+ subset_id="ted_en_id",
86
+ ),
87
+ ]
88
+
89
+ DEFAULT_CONFIG_NAME = "ted_en_id_source"
90
+
91
+ def _info(self):
92
+ if self.config.schema == "source":
93
+ features = datasets.Features({"id": datasets.Value("string"), "text": datasets.Value("string"), "label": datasets.Value("string")})
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(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
106
+ base_path = Path(dl_manager.download_and_extract(_URLs["indonlg"])) / "IndoNLG_downstream_tasks" / "MT_TED_MULTI"
107
+ data_files = {
108
+ "train": base_path / "train_preprocess.json",
109
+ "validation": base_path / "valid_preprocess.json",
110
+ "test": base_path / "test_preprocess.json",
111
+ }
112
+
113
+ return [
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.TRAIN,
116
+ gen_kwargs={"filepath": data_files["train"]},
117
+ ),
118
+ datasets.SplitGenerator(
119
+ name=datasets.Split.VALIDATION,
120
+ gen_kwargs={"filepath": data_files["validation"]},
121
+ ),
122
+ datasets.SplitGenerator(
123
+ name=datasets.Split.TEST,
124
+ gen_kwargs={"filepath": data_files["test"]},
125
+ ),
126
+ ]
127
+
128
+ def _generate_examples(self, filepath: Path):
129
+ data = json.load(open(filepath, "r"))
130
+ if self.config.schema == "source":
131
+ for row in data:
132
+ ex = {"id": row["id"], "text": row["text"], "label": row["label"]}
133
+ yield row["id"], ex
134
+ elif self.config.schema == "nusantara_t2t":
135
+ for row in data:
136
+ ex = {
137
+ "id": row["id"],
138
+ "text_1": row["text"],
139
+ "text_2": row["label"],
140
+ "text_1_name": "eng",
141
+ "text_2_name": "ind",
142
+ }
143
+ yield row["id"], ex
144
+ else:
145
+ raise ValueError(f"Invalid config: {self.config.name}")
146
+
147
+
148
+ if __name__ == "__main__":
149
+ datasets.load_dataset(__file__)