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# 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 |
+
from pathlib import Path
|
| 17 |
+
from typing import Dict, List, Tuple
|
| 18 |
+
|
| 19 |
+
import datasets
|
| 20 |
+
import pandas as pd
|
| 21 |
+
|
| 22 |
+
from seacrowd.utils import schemas
|
| 23 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 24 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
| 25 |
+
|
| 26 |
+
_CITATION = """\
|
| 27 |
+
@InProceedings{10.1007/978-981-16-8515-6_44,
|
| 28 |
+
author="Juan, Sarah Samson
|
| 29 |
+
and Saee, Suhaila
|
| 30 |
+
and Mohamad, Fitri",
|
| 31 |
+
editor="Alfred, Rayner
|
| 32 |
+
and Lim, Yuto",
|
| 33 |
+
title="Social Versus Physical Distancing: Analysis of Public Health Messages at the Start of COVID-19 Outbreak in Malaysia Using Natural Language Processing",
|
| 34 |
+
booktitle="Proceedings of the 8th International Conference on Computational Science and Technology",
|
| 35 |
+
year="2022",
|
| 36 |
+
publisher="Springer Singapore",
|
| 37 |
+
address="Singapore",
|
| 38 |
+
pages="577--589",
|
| 39 |
+
abstract="The study presents an attempt to analyse how social media netizens in Malaysia responded to the calls for ``Social Distancing'' and ``Physical Distancing'' as the newly recommended social norm was introduced to the world
|
| 40 |
+
as a response to the COVID-19 global pandemic. The pandemic drove a sharp increase in social media platforms' use as a public health communication platform since the first wave of the COVID-19 outbreak in Malaysia in April 2020.
|
| 41 |
+
We analysed thousands of tweets posted by Malaysians daily between January 2020 and August 2021 to determine public perceptions and interactions patterns. The analysis focused on positive and negative reactions
|
| 42 |
+
and the interchanges of uses of the recommended terminologies ``social distancing'' and ``physical distancing''. Using linguistic analysis and natural language processing,
|
| 43 |
+
findings dominantly indicate influences from the multilingual and multicultural values held by Malaysian netizens, as they embrace the concept of distancing as a measure of global public health safety.",
|
| 44 |
+
isbn="978-981-16-8515-6"
|
| 45 |
+
}
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
_DATASETNAME = "malaysia_tweets"
|
| 49 |
+
_DESCRIPTION = """\
|
| 50 |
+
This tweet data was extracted from tweets in Malaysia based on keywords
|
| 51 |
+
"social distancing" and "physical distancing". We conducted
|
| 52 |
+
sentiment analysis to understand public opinions on health messages
|
| 53 |
+
during the COVID-19 pandemic. Tweets from January 2020 to July 2021
|
| 54 |
+
were extracted using Python module snscrape and sentiments were obtained
|
| 55 |
+
automatically using Polyglot and MALAYA NLP tools due to multilingual data.
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
_HOMEPAGE = "https://github.com/sarahjuan/malaysia-tweets-with-sentiment-labels"
|
| 59 |
+
|
| 60 |
+
_LANGUAGES = ["zlm,", "eng"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
| 61 |
+
|
| 62 |
+
_LICENSE = Licenses.UNKNOWN.value # example: Licenses.MIT.value, Licenses.CC_BY_NC_SA_4_0.value, Licenses.UNLICENSE.value, Licenses.UNKNOWN.value
|
| 63 |
+
|
| 64 |
+
_LOCAL = False
|
| 65 |
+
|
| 66 |
+
_URLS = {
|
| 67 |
+
_DATASETNAME: "https://raw.githubusercontent.com/sarahjuan/malaysia-tweets-with-sentiment-labels/main/data/cleaned_tweets_sentiments.csv",
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS] # example: [Tasks.TRANSLATION, Tasks.NAMED_ENTITY_RECOGNITION, Tasks.RELATION_EXTRACTION]
|
| 71 |
+
|
| 72 |
+
_SOURCE_VERSION = "1.0.0"
|
| 73 |
+
|
| 74 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class MalaysiaTweetsDataset(datasets.GeneratorBasedBuilder):
|
| 78 |
+
"""This tweet data was extracted from tweets in Malaysia based on keywords
|
| 79 |
+
"social distancing" and "physical distancing" from January 2020 to July 2021."""
|
| 80 |
+
|
| 81 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 82 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
| 83 |
+
|
| 84 |
+
SEACROWD_SCHEMA_NAME = "text"
|
| 85 |
+
|
| 86 |
+
BUILDER_CONFIGS = [
|
| 87 |
+
SEACrowdConfig(
|
| 88 |
+
name=f"{_DATASETNAME}_source",
|
| 89 |
+
version=SOURCE_VERSION,
|
| 90 |
+
description=f"{_DATASETNAME} source schema",
|
| 91 |
+
schema="source",
|
| 92 |
+
subset_id=f"{_DATASETNAME}",
|
| 93 |
+
),
|
| 94 |
+
SEACrowdConfig(
|
| 95 |
+
name=f"{_DATASETNAME}_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
| 96 |
+
version=SEACROWD_VERSION,
|
| 97 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
| 98 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
| 99 |
+
subset_id=f"{_DATASETNAME}",
|
| 100 |
+
),
|
| 101 |
+
]
|
| 102 |
+
|
| 103 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
| 104 |
+
SENTIMENT_LABEL_CLASSES = ["POSITIVE", "NEGATIVE", "NEUTRAL"]
|
| 105 |
+
|
| 106 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 107 |
+
if self.config.schema == "source":
|
| 108 |
+
features = datasets.Features(
|
| 109 |
+
{
|
| 110 |
+
"Tweet": datasets.Value("string"),
|
| 111 |
+
"Sentiment": datasets.ClassLabel(names=self.SENTIMENT_LABEL_CLASSES),
|
| 112 |
+
}
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
| 116 |
+
features = schemas.text_features(self.SENTIMENT_LABEL_CLASSES)
|
| 117 |
+
|
| 118 |
+
return datasets.DatasetInfo(
|
| 119 |
+
description=_DESCRIPTION,
|
| 120 |
+
features=features,
|
| 121 |
+
homepage=_HOMEPAGE,
|
| 122 |
+
license=_LICENSE,
|
| 123 |
+
citation=_CITATION,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 127 |
+
"""Returns SplitGenerators."""
|
| 128 |
+
|
| 129 |
+
urls = _URLS[_DATASETNAME]
|
| 130 |
+
data_dir = dl_manager.download_and_extract(urls)
|
| 131 |
+
|
| 132 |
+
return [
|
| 133 |
+
datasets.SplitGenerator(
|
| 134 |
+
name=datasets.Split.TRAIN,
|
| 135 |
+
gen_kwargs={
|
| 136 |
+
"filepath": data_dir,
|
| 137 |
+
"split": "train",
|
| 138 |
+
},
|
| 139 |
+
)
|
| 140 |
+
]
|
| 141 |
+
|
| 142 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
| 143 |
+
"""Yields examples as (key, example) tuples."""
|
| 144 |
+
|
| 145 |
+
df = pd.read_csv(filepath, encoding="utf-8")
|
| 146 |
+
if self.config.schema == "source":
|
| 147 |
+
for idx, row in df.iterrows():
|
| 148 |
+
yield idx, dict(row)
|
| 149 |
+
|
| 150 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
| 151 |
+
for idx, row in df.iterrows():
|
| 152 |
+
yield idx, {"id": idx, "text": row["Tweet"], "label": row["Sentiment"]}
|