holylovenia commited on
Commit
770d214
·
1 Parent(s): c624cb4

Upload news_en_id.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. news_en_id.py +127 -0
news_en_id.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "news_en_id"
12
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
13
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
14
+
15
+ _LANGUAGES = ["ind", "eng"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
16
+ _LOCAL = False
17
+ _CITATION = """\
18
+ @inproceedings{guntara-etal-2020-benchmarking,
19
+ title = "Benchmarking Multidomain {E}nglish-{I}ndonesian Machine Translation",
20
+ author = "Guntara, Tri Wahyu and
21
+ Aji, Alham Fikri and
22
+ Prasojo, Radityo Eko",
23
+ booktitle = "Proceedings of the 13th Workshop on Building and Using Comparable Corpora",
24
+ month = may,
25
+ year = "2020",
26
+ address = "Marseille, France",
27
+ publisher = "European Language Resources Association",
28
+ url = "https://aclanthology.org/2020.bucc-1.6",
29
+ pages = "35--43",
30
+ language = "English",
31
+ ISBN = "979-10-95546-42-9",
32
+ }
33
+ """
34
+
35
+ _DESCRIPTION = """\
36
+ News En-Id is a machine translation dataset containing Indonesian-English parallel sentences collected from the news. The news dataset is collected from multiple sources: Pan Asia Networking Localization (PANL), Bilingual BBC news articles, Berita Jakarta, and GlobalVoices. 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.
37
+ """
38
+
39
+ _HOMEPAGE = "https://github.com/gunnxx/indonesian-mt-data"
40
+
41
+ _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
42
+
43
+ _URLs = {"indonlg": "https://storage.googleapis.com/babert-pretraining/IndoNLG_finals/downstream_task/downstream_task_datasets.zip"}
44
+
45
+ _SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION]
46
+
47
+ _SOURCE_VERSION = "1.0.0"
48
+ _NUSANTARA_VERSION = "1.0.0"
49
+
50
+
51
+ class NewsEnId(datasets.GeneratorBasedBuilder):
52
+ """Bible Su-Id is a machine translation dataset containing Indonesian-Sundanese parallel sentences collected from the bible.."""
53
+
54
+ BUILDER_CONFIGS = [
55
+ NusantaraConfig(
56
+ name="news_en_id_source",
57
+ version=datasets.Version(_SOURCE_VERSION),
58
+ description="News En-Id source schema",
59
+ schema="source",
60
+ subset_id="news_en_id",
61
+ ),
62
+ NusantaraConfig(
63
+ name="news_en_id_nusantara_t2t",
64
+ version=datasets.Version(_NUSANTARA_VERSION),
65
+ description="News En-Id Nusantara schema",
66
+ schema="nusantara_t2t",
67
+ subset_id="news_en_id",
68
+ ),
69
+ ]
70
+
71
+ DEFAULT_CONFIG_NAME = "news_en_id_source"
72
+
73
+ def _info(self):
74
+ if self.config.schema == "source":
75
+ features = datasets.Features({"id": datasets.Value("string"), "text": datasets.Value("string"), "label": 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
+ base_path = Path(dl_manager.download_and_extract(_URLs["indonlg"])) / "IndoNLG_downstream_tasks" / "MT_IMD_NEWS"
89
+ data_files = {
90
+ "train": base_path / "train_preprocess.json",
91
+ "validation": base_path / "valid_preprocess.json",
92
+ "test": base_path / "test_preprocess.json",
93
+ }
94
+
95
+ return [
96
+ datasets.SplitGenerator(
97
+ name=datasets.Split.TRAIN,
98
+ gen_kwargs={"filepath": data_files["train"]},
99
+ ),
100
+ datasets.SplitGenerator(
101
+ name=datasets.Split.VALIDATION,
102
+ gen_kwargs={"filepath": data_files["validation"]},
103
+ ),
104
+ datasets.SplitGenerator(
105
+ name=datasets.Split.TEST,
106
+ gen_kwargs={"filepath": data_files["test"]},
107
+ ),
108
+ ]
109
+
110
+ def _generate_examples(self, filepath: Path):
111
+ data = json.load(open(filepath, "r"))
112
+ if self.config.schema == "source":
113
+ for row in data:
114
+ ex = {"id": row["id"], "text": row["text"], "label": row["label"]}
115
+ yield row["id"], ex
116
+ elif self.config.schema == "nusantara_t2t":
117
+ for row in data:
118
+ ex = {
119
+ "id": row["id"],
120
+ "text_1": row["text"],
121
+ "text_2": row["label"],
122
+ "text_1_name": "eng",
123
+ "text_2_name": "ind",
124
+ }
125
+ yield row["id"], ex
126
+ else:
127
+ raise ValueError(f"Invalid config: {self.config.name}")