File size: 8,701 Bytes
467b100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239dd64
467b100
 
 
 
 
 
 
239dd64
 
 
467b100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239dd64
467b100
 
 
 
 
 
 
 
 
 
 
 
 
 
239dd64
467b100
 
239dd64
467b100
 
 
 
 
 
239dd64
 
 
 
 
467b100
 
239dd64
 
 
 
 
467b100
 
239dd64
 
 
 
 
467b100
 
 
 
 
 
 
 
 
 
 
 
 
239dd64
467b100
239dd64
467b100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239dd64
467b100
 
 
 
 
 
 
 
 
 
 
239dd64
467b100
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# coding=utf-8
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Code-mixed sentiment analysis of Indonesian language and Javanese language
using Lexicon based approach

Nowadays mixing one language with another language either in spoken or written
communication has become a common practice for bilingual speakers in daily
conversation as well as in social media. Lexicon based approach is one of the
approaches in extracting the sentiment analysis. This study is aimed to compare
two lexicon models which are SentiNetWord and VADER in extracting the polarity
of the code-mixed sentences in Indonesian language and Javanese language. 3,963
tweets were gathered from two accounts that provide code-mixed tweets.
Pre-processing such as removing duplicates, translating to English, filter
special characters, transform lower case and filter stop words were conducted
on the tweets. Positive and negative word score from lexicon model was then
calculated using simple mathematic formula in order to classify the polarity.
By comparing with the manual labelling, the result showed that SentiNetWord
perform better than VADER in negative sentiments. However, both of the lexicon
model did not perform well in neutral and positive sentiments. On overall
performance, VADER showed better performance than SentiNetWord. This study
showed that the reason for the misclassified was that most of Indonesian
language and Javanese language consist of words that were considered as
positive in both Lexicon model.

[seacrowd_schema_name] = (text, t2t)
"""
from pathlib import Path
from typing import Dict, List, Tuple

import datasets
import pandas as pd

from seacrowd.utils import schemas
from seacrowd.utils.configs import SEACrowdConfig
from seacrowd.utils.constants import Tasks

_CITATION = """\
@article{Tho_2021,
  doi = {10.1088/1742-6596/1869/1/012084},
  url = {https://doi.org/10.1088/1742-6596/1869/1/012084},
  year = 2021,
  month = {apr},
  publisher = {{IOP} Publishing},
  volume = {1869},
  number = {1},
  pages = {012084},
  author = {C Tho and Y Heryadi and L Lukas and A Wibowo},
  title = {Code-mixed sentiment analysis of Indonesian language and Javanese language using Lexicon based approach},
  journal = {Journal of Physics: Conference Series},
  abstract = {Nowadays mixing one language with another language either in
  spoken or written communication has become a common practice for bilingual
  speakers in daily conversation as well as in social media. Lexicon based
  approach is one of the approaches in extracting the sentiment analysis. This
  study is aimed to compare two lexicon models which are SentiNetWord and VADER
  in extracting the polarity of the code-mixed sentences in Indonesian language
  and Javanese language. 3,963 tweets were gathered from two accounts that
  provide code-mixed tweets. Pre-processing such as removing duplicates,
  translating to English, filter special characters, transform lower case and
  filter stop words were conducted on the tweets. Positive and negative word
  score from lexicon model was then calculated using simple mathematic formula
  in order to classify the polarity. By comparing with the manual labelling,
  the result showed that SentiNetWord perform better than VADER in negative
  sentiments. However, both of the lexicon model did not perform well in
  neutral and positive sentiments. On overall performance, VADER showed better
  performance than SentiNetWord. This study showed that the reason for the
  misclassified was that most of Indonesian language and Javanese language
  consist of words that were considered as positive in both Lexicon model.}
}
"""

_DATASETNAME = "code_mixed_jv_id"

_DESCRIPTION = """\
Sentiment analysis and machine translation data for Javanese and Indonesian.
"""

_HOMEPAGE = "https://iopscience.iop.org/article/10.1088/1742-6596/1869/1/012084"

_LICENSE = "cc_by_3.0"

_URLS = {
    _DATASETNAME: "https://docs.google.com/spreadsheets/d/1mq2VyPEDfXl7K6p5TbRPsaefYwkuy7RQ/export?format=csv&gid=356398080",
}

_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS, Tasks.MACHINE_TRANSLATION]

_SOURCE_VERSION = "1.0.0"

_SEACROWD_VERSION = "2024.06.20"

_LANGUAGES = ['jav', 'ind']
_LOCAL = False

LANGUAGES_COLUMNS = {
    "id": ("text_ind", "text_jav"),
    "jv": ("text_jav", "text_ind"),
}


class CodeMixedSenti(datasets.GeneratorBasedBuilder):
    """Code-mixed sentiment analysis for Indonesian and Javanese."""

    SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
    SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)

    BUILDER_CONFIGS = [
        SEACrowdConfig(
            name="code_mixed_jv_id_source",
            version=SOURCE_VERSION,
            description="code_mixed_jv_id source schema for Javanese and Indonesian",
            schema="source",
            subset_id="code_mixed_source",
        ),
        SEACrowdConfig(
            name="code_mixed_jv_id_jv_seacrowd_text",
            version=SEACROWD_VERSION,
            description="code_mixed_jv_id seacrowd_text schema for Javanese",
            schema="seacrowd_text",
            subset_id="code_mixed_jv",
        ),
        SEACrowdConfig(
            name="code_mixed_jv_id_id_seacrowd_text",
            version=SEACROWD_VERSION,
            description="code_mixed_jv_id seacrowd_text schema for Indonesian",
            schema="seacrowd_text",
            subset_id="code_mixed_id",
        ),
        SEACrowdConfig(
            name="code_mixed_jv_id_seacrowd_t2t",
            version=SEACROWD_VERSION,
            description="code_mixed_jv_id seacrowd_t2t schema for Javanese and Indonesian",
            schema="seacrowd_t2t",
            subset_id="code_mixed_jv_id",
        )
    ]

    DEFAULT_CONFIG_NAME = "code_mixed_id_jv_source"

    def _info(self) -> datasets.DatasetInfo:
        if self.config.schema == "source":
            features = datasets.Features({
                "text_jav": datasets.Value("string"),
                "text_ind": datasets.Value("string"),
                "label": datasets.Value("int32")
            })
        elif self.config.schema == "seacrowd_text":
            features = schemas.text_features(["-1", "0", "1"])
        elif self.config.schema == "seacrowd_t2t":
            features = schemas.text2text_features

        return datasets.DatasetInfo(description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION,)

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        """Returns SplitGenerators."""
        url = _URLS[_DATASETNAME]
        path = dl_manager.download_and_extract(url)
        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": path, "split": "train"}),
        ]

    def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
        df = pd.read_csv(filepath,
                         skiprows=1,
                         names=["text_jav", "label", "text_ind"])
        if self.config.schema == "source":
            i = 0
            for row in df.itertuples():
                ex = {"text_jav": row.text_jav, "text_ind": row.text_ind, "label": row.label}
                yield i, ex
                i += 1
        elif self.config.schema == "seacrowd_text":
            prefix_length = len(_DATASETNAME)
            start = prefix_length + 1
            end = prefix_length + 1 + 2
            language = self.config.name[start:end]
            keep_column, drop_column = LANGUAGES_COLUMNS[language]
            df = df.drop(columns=[drop_column]).rename(columns={keep_column: "text"})
            i = 0
            for row in df.itertuples():
                ex = {"id": str(i), "text": row.text, "label": str(row.label)}
                yield i, ex
                i += 1
        elif self.config.schema == "seacrowd_t2t":
            i = 0
            for row in df.itertuples():
                ex = {"id": str(i), "text_1": row.text_jav, "text_2": row.text_ind, "text_1_name": "jav", "text_2_name": "ind"}
                yield i, ex
                i += 1