Datasets:

Languages:
Thai
ArXiv:
License:
holylovenia commited on
Commit
9219c5b
·
verified ·
1 Parent(s): 3774846

Upload wisesight_thai_sentiment.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. wisesight_thai_sentiment.py +177 -0
wisesight_thai_sentiment.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ import json
17
+ import os
18
+
19
+ import datasets
20
+
21
+ from seacrowd.utils import schemas
22
+ from seacrowd.utils.configs import SEACrowdConfig
23
+ from seacrowd.utils.constants import (DEFAULT_SEACROWD_VIEW_NAME,
24
+ DEFAULT_SOURCE_VIEW_NAME, Licenses,
25
+ Tasks)
26
+
27
+ _CITATION = """\
28
+ @software{bact_2019_3457447,
29
+ author = {Suriyawongkul, Arthit and
30
+ Chuangsuwanich, Ekapol and
31
+ Chormai, Pattarawat and
32
+ Polpanumas, Charin},
33
+ title = {PyThaiNLP/wisesight-sentiment: First release},
34
+ month = sep,
35
+ year = 2019,
36
+ publisher = {Zenodo},
37
+ version = {v1.0},
38
+ doi = {10.5281/zenodo.3457447},
39
+ url = {https://doi.org/10.5281/zenodo.3457447}
40
+ }
41
+ """
42
+
43
+
44
+ _DATASETNAME = "wisesight_thai_sentiment"
45
+
46
+
47
+ _DESCRIPTION = """\
48
+ Wisesight Sentiment Corpus: Social media messages in Thai language with sentiment category (positive, neutral, negative, question)
49
+ * Released to public domain under Creative Commons Zero v1.0 Universal license.
50
+ * Category (Labels): {"pos": 0, "neu": 1, "neg": 2, "q": 3}
51
+ * Size: 26,737 messages
52
+ * Language: Central Thai
53
+ * Style: Informal and conversational. With some news headlines and advertisement.
54
+ * Time period: Around 2016 to early 2019. With small amount from other period.
55
+ * Domains: Mixed. Majority are consumer products and services (restaurants, cosmetics, drinks, car, hotels), with some current affairs.
56
+ * Privacy:
57
+ * Only messages that made available to the public on the internet (websites, blogs, social network sites).
58
+ * For Facebook, this means the public comments (everyone can see) that made on a public page.
59
+ * Private/protected messages and messages in groups, chat, and inbox are not included.
60
+ * Alternations and modifications:
61
+ * Keep in mind that this corpus does not statistically represent anything in the language register.
62
+ * Large amount of messages are not in their original form. Personal data are removed or masked.
63
+ * Duplicated, leading, and trailing whitespaces are removed. Other punctuations, symbols, and emojis are kept intact.
64
+ (Mis)spellings are kept intact.
65
+ * Messages longer than 2,000 characters are removed.
66
+ * Long non-Thai messages are removed. Duplicated message (exact match) are removed.
67
+ * More characteristics of the data can be explore: https://github.com/PyThaiNLP/wisesight-sentiment/blob/master/exploration.ipynb
68
+ """
69
+
70
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
71
+ _UNIFIED_VIEW_NAME = DEFAULT_SEACROWD_VIEW_NAME
72
+
73
+ _HOMEPAGE = "https://github.com/PyThaiNLP/wisesight-sentiment"
74
+
75
+ _LANGUAGES = ["tha"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
76
+
77
+
78
+ _LICENSE = Licenses.CC0_1_0.value
79
+
80
+
81
+ _LOCAL = False
82
+
83
+
84
+ _URLS = {
85
+ _DATASETNAME: "https://github.com/PyThaiNLP/wisesight-sentiment/raw/master/huggingface/data.zip",
86
+ }
87
+
88
+
89
+ _SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS] # example: [Tasks.TRANSLATION, Tasks.NAMED_ENTITY_RECOGNITION, Tasks.RELATION_EXTRACTION]
90
+
91
+
92
+ _SOURCE_VERSION = "1.0.0"
93
+
94
+ _SEACROWD_VERSION = "2024.06.20"
95
+
96
+
97
+ class WisesightSentimentDataset(datasets.GeneratorBasedBuilder):
98
+ """Wisesight Sentiment Corpus: Social media messages in Thai language with sentiment category (positive, neutral, negative, question)"""
99
+
100
+ _DOWNLOAD_URL = _URLS[_DATASETNAME]
101
+ _TRAIN_FILE = "train.jsonl"
102
+ _VAL_FILE = "valid.jsonl"
103
+ _TEST_FILE = "test.jsonl"
104
+
105
+ BUILDER_CONFIGS = [
106
+ SEACrowdConfig(
107
+ name="wisesight_thai_sentiment_source",
108
+ version=datasets.Version(_SOURCE_VERSION),
109
+ description="Wisesight Sentiment Corpus Source version (positive, neutral, negative, question)",
110
+ schema="source",
111
+ subset_id="wisesight_thai_sentiment",
112
+ ),
113
+ SEACrowdConfig(
114
+ name="wisesight_thai_sentiment_seacrowd_text",
115
+ version=datasets.Version(_SEACROWD_VERSION),
116
+ description="Wisesight Sentiment Corpus Seacrowd version (positive, neutral, negative, question)",
117
+ schema="seacrowd_text",
118
+ subset_id="wisesight_thai_sentiment",
119
+ ),
120
+ ]
121
+
122
+ DEFAULT_CONFIG_NAME = "wisesight_thai_sentiment_source"
123
+
124
+ def _info(self):
125
+ if self.config.schema == "source":
126
+ features = datasets.Features(
127
+ {
128
+ "texts": datasets.Value("string"),
129
+ "category": datasets.features.ClassLabel(names=["pos", "neu", "neg", "q"]),
130
+ }
131
+ )
132
+ elif self.config.schema == "seacrowd_text":
133
+ features = schemas.text_features(["pos", "neu", "neg", "q"])
134
+
135
+ return datasets.DatasetInfo(
136
+ description=_DESCRIPTION,
137
+ features=features,
138
+ homepage=_HOMEPAGE,
139
+ license=_LICENSE,
140
+ citation=_CITATION,
141
+ )
142
+
143
+ def _split_generators(self, dl_manager):
144
+ arch_path = dl_manager.download_and_extract(self._DOWNLOAD_URL)
145
+ data_dir = os.path.join(arch_path, "data")
146
+ return [
147
+ datasets.SplitGenerator(
148
+ name=datasets.Split.TRAIN,
149
+ gen_kwargs={"filepath": os.path.join(data_dir, self._TRAIN_FILE)},
150
+ ),
151
+ datasets.SplitGenerator(
152
+ name=datasets.Split.VALIDATION,
153
+ gen_kwargs={"filepath": os.path.join(data_dir, self._VAL_FILE)},
154
+ ),
155
+ datasets.SplitGenerator(
156
+ name=datasets.Split.TEST,
157
+ gen_kwargs={"filepath": os.path.join(data_dir, self._TEST_FILE)},
158
+ ),
159
+ ]
160
+
161
+ def _generate_examples(self, filepath):
162
+ """Generate WisesightSentiment examples."""
163
+ with open(filepath, encoding="utf-8") as f:
164
+ if self.config.schema == "source":
165
+ for id_, row in enumerate(f):
166
+ data = json.loads(row)
167
+ texts = data["texts"]
168
+ category = data["category"]
169
+ yield id_, {"texts": texts, "category": category}
170
+
171
+ elif self.config.schema == "seacrowd_text":
172
+ for id_, row in enumerate(f):
173
+ data = json.loads(row)
174
+ texts = data["texts"]
175
+ category = data["category"]
176
+ ex = {"id": str(id_), "text": texts, "label": category}
177
+ yield id_, ex