holylovenia commited on
Commit
857feaa
1 Parent(s): dc4e629

Upload id_sent_emo_mobile_apps.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. id_sent_emo_mobile_apps.py +136 -0
id_sent_emo_mobile_apps.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ from pathlib import Path
16
+ from typing import Dict, List, Tuple
17
+
18
+ import datasets
19
+ import pandas as pd
20
+
21
+ from seacrowd.utils import schemas
22
+ from seacrowd.utils.configs import SEACrowdConfig
23
+ from seacrowd.utils.constants import Licenses, Tasks
24
+
25
+ _CITATION = """
26
+ @article{riccosan2023,
27
+ author = {Riccosan and Saputra, Karen Etania},
28
+ title = {Multilabel multiclass sentiment and emotion dataset from indonesian mobile application review},
29
+ journal = {Data in Brief},
30
+ volume = {50},
31
+ year = {2023},
32
+ doi = {10.1016/j.dib.2023.109576},
33
+ }
34
+ """
35
+
36
+ _LOCAL = False
37
+ _LANGUAGES = ["ind"]
38
+ _DATASETNAME = "id_sent_emo_mobile_apps"
39
+ _DESCRIPTION = """
40
+ This dataset contains manually annotated public reviews of mobile applications in Indonesia.
41
+ Each review is given a sentiment label (positive, negative, neutral) and
42
+ an emotion label (anger, sadness, fear, happiness, love, neutral).
43
+ """
44
+ _HOMEPAGE = "https://github.com/Ricco48/Multilabel-Sentiment-and-Emotion-Dataset-from-Indonesian-" "Mobile-Application-Review/tree/CreateCodeForPaper"
45
+ _LICENSE = Licenses.CC_BY_NC_ND_4_0.value
46
+ _URL = (
47
+ "https://github.com/Ricco48/Multilabel-Sentiment-and-Emotion-Dataset-from-Indonesian-Mobile-Application-Review/raw/CreateCodeForPaper/"
48
+ "Multilabel%20Sentiment%20and%20Emotion%20Dataset%20from%20Indonesian%20Mobile%20Application%20Review/Multilabel%20Sentiment%20and%20Emotion"
49
+ "%20Dataset%20from%20Indonesian%20Mobile%20Application%20Review.csv"
50
+ )
51
+
52
+ _SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS, Tasks.EMOTION_CLASSIFICATION]
53
+ _SOURCE_VERSION = "1.0.0"
54
+ _SEACROWD_VERSION = "2024.06.20"
55
+
56
+
57
+ class EmoSentIndMobile(datasets.GeneratorBasedBuilder):
58
+ """Dataset of Indonesian mobile application reviews manually annotated for emotion and sentiment."""
59
+
60
+ SUBSETS = ["emotion", "sentiment"]
61
+ EMOTION_CLASS_LABELS = ["Sad", "Anger", "Fear", "Happy", "Love", "Neutral"]
62
+ SENTIMENT_CLASS_LABELS = ["Negative", "Positive", "Neutral"]
63
+
64
+ BUILDER_CONFIGS = [
65
+ SEACrowdConfig(
66
+ name=f"{_DATASETNAME}_source",
67
+ version=datasets.Version(_SOURCE_VERSION),
68
+ description=f"{_DATASETNAME} source schema",
69
+ schema="source",
70
+ subset_id=_DATASETNAME
71
+ )
72
+ ] + [
73
+ SEACrowdConfig(
74
+ name=f"{_DATASETNAME}_{subset}_seacrowd_text",
75
+ version=datasets.Version(_SEACROWD_VERSION),
76
+ description=f"{_DATASETNAME} SEACrowd schema for {subset} subset",
77
+ schema="seacrowd_text",
78
+ subset_id=f"{_DATASETNAME}_{subset}",
79
+ )
80
+ for subset in SUBSETS
81
+ ]
82
+
83
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
84
+
85
+ def _info(self) -> datasets.DatasetInfo:
86
+ if self.config.schema == "source":
87
+ features = datasets.Features(
88
+ {
89
+ "content": datasets.Value("string"),
90
+ "sentiment": datasets.Value("string"),
91
+ "emotion": datasets.Value("string"),
92
+ }
93
+ )
94
+
95
+ elif self.config.schema == "seacrowd_text":
96
+ if "emotion" in self.config.subset_id:
97
+ labels = self.EMOTION_CLASS_LABELS
98
+ elif "sentiment" in self.config.subset_id:
99
+ labels = self.SENTIMENT_CLASS_LABELS
100
+ features = schemas.text_features(label_names=labels)
101
+
102
+ return datasets.DatasetInfo(
103
+ description=_DESCRIPTION,
104
+ features=features,
105
+ homepage=_HOMEPAGE,
106
+ license=_LICENSE,
107
+ citation=_CITATION,
108
+ )
109
+
110
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
111
+ """Returns SplitGenerators."""
112
+ fp = dl_manager.download(_URL)
113
+ return [
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.TRAIN,
116
+ gen_kwargs={"filepath": fp},
117
+ ),
118
+ ]
119
+
120
+ def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
121
+ """Yields examples as (key, example) tuples."""
122
+ df = pd.read_csv(filepath, sep="\t", index_col=None)
123
+ for index, row in df.iterrows():
124
+ if self.config.schema == "source":
125
+ example = {
126
+ "content": row["content"],
127
+ "sentiment": row["Sentiment"].title(),
128
+ "emotion": row["Emotion"].title(),
129
+ }
130
+ elif self.config.schema == "seacrowd_text":
131
+ if "emotion" in self.config.subset_id:
132
+ label = row["Emotion"]
133
+ elif "sentiment" in self.config.subset_id:
134
+ label = row["Sentiment"]
135
+ example = {"id": str(index), "text": row["content"], "label": label.title()}
136
+ yield index, example