holylovenia commited on
Commit
dda341c
1 Parent(s): 550e0c7

Upload imdb_jv.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. imdb_jv.py +149 -0
imdb_jv.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pathlib import Path
3
+ from typing import Dict, List, Tuple
4
+
5
+ import datasets
6
+
7
+ from nusacrowd.utils.configs import NusantaraConfig
8
+ from nusacrowd.utils.constants import Tasks
9
+ from nusacrowd.utils import schemas
10
+ import pandas as pd
11
+
12
+ _CITATION = """\
13
+ @inproceedings{wongso2021causal,
14
+ title={Causal and masked language modeling of Javanese language using transformer-based architectures},
15
+ author={Wongso, Wilson and Setiawan, David Samuel and Suhartono, Derwin},
16
+ booktitle={2021 International Conference on Advanced Computer Science and Information Systems (ICACSIS)},
17
+ pages={1--7},
18
+ year={2021},
19
+ organization={IEEE}
20
+ }
21
+ """
22
+
23
+ _DATASETNAME = "imdb_jv"
24
+
25
+ _DESCRIPTION = """\
26
+ Javanese Imdb Movie Reviews Dataset is a Javanese version of the IMDb Movie Reviews dataset by translating the original English dataset to Javanese.
27
+ """
28
+
29
+ _HOMEPAGE = "https://huggingface.co/datasets/w11wo/imdb-javanese"
30
+
31
+ _LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
32
+ _LOCAL = False
33
+
34
+ _LICENSE = "Unknown"
35
+
36
+ _URLS = {
37
+ _DATASETNAME: "https://huggingface.co/datasets/w11wo/imdb-javanese/resolve/main/javanese_imdb_csv.zip",
38
+ }
39
+
40
+ _SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
41
+
42
+ _SOURCE_VERSION = "1.0.0"
43
+
44
+ _NUSANTARA_VERSION = "1.0.0"
45
+
46
+ class IMDbJv(datasets.GeneratorBasedBuilder):
47
+ """Javanese Imdb Movie Reviews Dataset is a Javanese version of the IMDb Movie Reviews dataset by translating the original English dataset to Javanese."""
48
+
49
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
50
+ NUSANTARA_VERSION = datasets.Version(_NUSANTARA_VERSION)
51
+
52
+ BUILDER_CONFIGS = [
53
+ NusantaraConfig(
54
+ name="imdb_jv_source",
55
+ version=datasets.Version(_SOURCE_VERSION),
56
+ description="imdb_jv source schema",
57
+ schema="source",
58
+ subset_id="imdb_jv",
59
+ ),
60
+ NusantaraConfig(
61
+ name="imdb_jv_nusantara_text",
62
+ version=datasets.Version(_NUSANTARA_VERSION),
63
+ description="imdb_jv Nusantara schema",
64
+ schema="nusantara_text",
65
+ subset_id="imdb_jv",
66
+ ),
67
+ ]
68
+
69
+ DEFAULT_CONFIG_NAME = "imdb_jv_source"
70
+
71
+ def _info(self) -> datasets.DatasetInfo:
72
+ if self.config.schema == "source":
73
+ features = datasets.Features(
74
+ {
75
+ "id": datasets.Value("string"),
76
+ "text": datasets.Value("string"),
77
+ "label": datasets.Value("string")
78
+ }
79
+ )
80
+ elif self.config.schema == "nusantara_text":
81
+ features = schemas.text_features(['1', '0', '-1'])
82
+
83
+ return datasets.DatasetInfo(
84
+ description=_DESCRIPTION,
85
+ features=features,
86
+ homepage=_HOMEPAGE,
87
+ license=_LICENSE,
88
+ citation=_CITATION,
89
+ )
90
+
91
+
92
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
93
+ data_dir = Path(dl_manager.download_and_extract(_URLS[_DATASETNAME]))
94
+
95
+ data_files = {
96
+ "train": "javanese_imdb_train.csv",
97
+ "unsupervised": "javanese_imdb_unsup.csv",
98
+ "test": "javanese_imdb_test.csv",
99
+ }
100
+
101
+ return [
102
+ datasets.SplitGenerator(
103
+ name=datasets.Split.TRAIN,
104
+
105
+ gen_kwargs={
106
+ "filepath": os.path.join(data_dir, data_files["train"]),
107
+ "split": "train",
108
+ },
109
+ ),
110
+ datasets.SplitGenerator(
111
+ name="unsupervised",
112
+ gen_kwargs={
113
+ "filepath": os.path.join(data_dir, data_files["unsupervised"]),
114
+ "split": "unsupervised",
115
+ },
116
+ ),
117
+ datasets.SplitGenerator(
118
+ name=datasets.Split.TEST,
119
+ gen_kwargs={
120
+ "filepath": os.path.join(data_dir, data_files["test"]),
121
+ "split": "test",
122
+ },
123
+ ),
124
+ ]
125
+
126
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
127
+ if self.config.schema == "source":
128
+ data = pd.read_csv(filepath)
129
+ length = len(data['label'])
130
+ for id in range(length):
131
+ ex = {
132
+ "id": str(id),
133
+ "text": data['text'][id],
134
+ "label": data['label'][id],
135
+ }
136
+ yield id, ex
137
+
138
+ elif self.config.schema == "nusantara_text":
139
+ data = pd.read_csv(filepath)
140
+ length = len(data['label'])
141
+ for id in range(length):
142
+ ex = {
143
+ "id": str(id),
144
+ "text": data['text'][id],
145
+ "label": data['label'][id],
146
+ }
147
+ yield id, ex
148
+ else:
149
+ raise ValueError(f"Invalid config: {self.config.name}")