holylovenia commited on
Commit
44e818d
1 Parent(s): 58105e9

Upload emot.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. emot.py +137 -0
emot.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+ import datasets
5
+ import pandas as pd
6
+
7
+ from nusacrowd.utils import schemas
8
+ from nusacrowd.utils.configs import NusantaraConfig
9
+ from nusacrowd.utils.constants import DEFAULT_NUSANTARA_VIEW_NAME, DEFAULT_SOURCE_VIEW_NAME, Tasks
10
+
11
+ _DATASETNAME = "emot"
12
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
13
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
14
+
15
+ _LANGUAGES = ["ind"] # We follow ISO639-3 langauge code (https://iso639-3.sil.org/code_tables/639/data)
16
+ _LOCAL = False
17
+ _CITATION = """\
18
+ @inproceedings{saputri2018emotion,
19
+ title={Emotion classification on indonesian twitter dataset},
20
+ author={Saputri, Mei Silviana and Mahendra, Rahmad and Adriani, Mirna},
21
+ booktitle={2018 International Conference on Asian Language Processing (IALP)},
22
+ pages={90--95},
23
+ year={2018},
24
+ organization={IEEE}
25
+ }
26
+
27
+ @inproceedings{wilie2020indonlu,
28
+ title={IndoNLU: Benchmark and Resources for Evaluating Indonesian Natural Language Understanding},
29
+ author={Wilie, Bryan and Vincentio, Karissa and Winata, Genta Indra and Cahyawijaya, Samuel and Li, Xiaohong and Lim, Zhi Yuan and Soleman, Sidik and Mahendra, Rahmad and Fung, Pascale and Bahar, Syafri and others},
30
+ booktitle={Proceedings of the 1st Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the 10th International Joint Conference on Natural Language Processing},
31
+ pages={843--857},
32
+ year={2020}
33
+ }
34
+ """
35
+
36
+ _DESCRIPTION = """\
37
+ EmoT is an emotion classification dataset collected from the social media platform Twitter. The dataset consists of around 4000 Indonesian colloquial language tweets, covering five different emotion labels: anger, fear, happiness, love, and sadness.
38
+ EmoT dataset is splitted into 3 sets with 3521 train, 440 validation, 442 test data.
39
+ """
40
+
41
+ _HOMEPAGE = "https://github.com/IndoNLP/indonlu"
42
+
43
+ _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
44
+
45
+ _URLs = {
46
+ "train": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/emot_emotion-twitter/train_preprocess.csv",
47
+ "validation": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/emot_emotion-twitter/valid_preprocess.csv",
48
+ "test": "https://raw.githubusercontent.com/IndoNLP/indonlu/master/dataset/emot_emotion-twitter/test_preprocess.csv",
49
+ }
50
+
51
+ _SUPPORTED_TASKS = [Tasks.EMOTION_CLASSIFICATION]
52
+
53
+ _SOURCE_VERSION = "1.0.0"
54
+ _NUSANTARA_VERSION = "1.0.0"
55
+
56
+
57
+ class EmoT(datasets.GeneratorBasedBuilder):
58
+ """SMSA is a sentiment analysis dataset consisting of 3 labels (positive, neutral, and negative) which comes from comments and reviews collected from multiple online platforms."""
59
+
60
+ BUILDER_CONFIGS = [
61
+ NusantaraConfig(
62
+ name="emot_source",
63
+ version=datasets.Version(_SOURCE_VERSION),
64
+ description="EmoT source schema",
65
+ schema="source",
66
+ subset_id="emot",
67
+ ),
68
+ NusantaraConfig(
69
+ name="emot_nusantara_text",
70
+ version=datasets.Version(_NUSANTARA_VERSION),
71
+ description="EmoT Nusantara schema",
72
+ schema="nusantara_text",
73
+ subset_id="emot",
74
+ ),
75
+ ]
76
+
77
+ DEFAULT_CONFIG_NAME = "emot_source"
78
+
79
+ def _info(self):
80
+ if self.config.schema == "source":
81
+ features = datasets.Features(
82
+ {
83
+ "index": datasets.Value("string"),
84
+ "tweet": datasets.Value("string"),
85
+ "label": datasets.Value("string"),
86
+ }
87
+ )
88
+ elif self.config.schema == "nusantara_text":
89
+ features = schemas.text_features(["happy", "love", "fear", "anger", "sadness"])
90
+
91
+ return datasets.DatasetInfo(
92
+ description=_DESCRIPTION,
93
+ features=features,
94
+ homepage=_HOMEPAGE,
95
+ license=_LICENSE,
96
+ citation=_CITATION,
97
+ )
98
+
99
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
100
+ train_tsv_path = Path(dl_manager.download_and_extract(_URLs["train"]))
101
+ validation_tsv_path = Path(dl_manager.download_and_extract(_URLs["validation"]))
102
+ test_tsv_path = Path(dl_manager.download_and_extract(_URLs["test"]))
103
+ data_files = {
104
+ "train": train_tsv_path,
105
+ "validation": validation_tsv_path,
106
+ "test": test_tsv_path,
107
+ }
108
+
109
+ return [
110
+ datasets.SplitGenerator(
111
+ name=datasets.Split.TRAIN,
112
+ gen_kwargs={"filepath": data_files["train"]},
113
+ ),
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.VALIDATION,
116
+ gen_kwargs={"filepath": data_files["validation"]},
117
+ ),
118
+ datasets.SplitGenerator(
119
+ name=datasets.Split.TEST,
120
+ gen_kwargs={"filepath": data_files["test"]},
121
+ ),
122
+ ]
123
+
124
+ def _generate_examples(self, filepath: Path):
125
+ df = pd.read_csv(filepath, sep=",", header="infer").reset_index()
126
+ df.columns = ["id", "label", "tweet"]
127
+
128
+ if self.config.schema == "source":
129
+ for row in df.itertuples():
130
+ ex = {"index": str(row.id), "tweet": row.tweet, "label": row.label}
131
+ yield row.id, ex
132
+ elif self.config.schema == "nusantara_text":
133
+ for row in df.itertuples():
134
+ ex = {"id": str(row.id), "text": row.tweet, "label": row.label}
135
+ yield row.id, ex
136
+ else:
137
+ raise ValueError(f"Invalid config: {self.config.name}")