Upload id_vaccines_tweets.py with huggingface_hub
Browse files- id_vaccines_tweets.py +113 -0
id_vaccines_tweets.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
import pandas
|
| 3 |
+
|
| 4 |
+
from seacrowd.utils import schemas
|
| 5 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 6 |
+
from seacrowd.utils.constants import (DEFAULT_SEACROWD_VIEW_NAME,
|
| 7 |
+
DEFAULT_SOURCE_VIEW_NAME, Tasks, Licenses)
|
| 8 |
+
|
| 9 |
+
_DATASETNAME = "id_vaccines_tweets"
|
| 10 |
+
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
| 11 |
+
_UNIFIED_VIEW_NAME = DEFAULT_SEACROWD_VIEW_NAME
|
| 12 |
+
|
| 13 |
+
_LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
| 14 |
+
_LOCAL = False
|
| 15 |
+
_CITATION = """\
|
| 16 |
+
@article{febriyanti2021analisis,
|
| 17 |
+
title={ANALISIS SENTIMEN MASYARAKAT INDONESIA TERHADAP PELAKSANAAN VAKSIN COVID'19},
|
| 18 |
+
author={Febriyanti, Syintya and Nursidah, Dea Ratu and Gustiara, Dela and Yulianti, Rika},
|
| 19 |
+
journal={Khazanah: Jurnal Mahasiswa},
|
| 20 |
+
volume={13},
|
| 21 |
+
number={2},
|
| 22 |
+
year={2021}
|
| 23 |
+
}
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
_DESCRIPTION = """\
|
| 27 |
+
Dataset containing tweets about COVID-19 vaccines with manually labelled information about whether they are a
|
| 28 |
+
subjective tweet and their sentiment polarity. Tweets are from 20-27 June 2021 and 15-22 July 2021.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
_HOMEPAGE = "https://github.com/rayendito/id-vaccines-tweets"
|
| 32 |
+
|
| 33 |
+
_LICENSE = Licenses.UNKNOWN.value
|
| 34 |
+
|
| 35 |
+
_URL = "https://raw.githubusercontent.com/rayendito/id-vaccines-tweets/main/id_vaccines_tweets.csv"
|
| 36 |
+
|
| 37 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
|
| 38 |
+
_SOURCE_VERSION = "1.0.0"
|
| 39 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class IdVaccinesTweetsDataset(datasets.GeneratorBasedBuilder):
|
| 43 |
+
"""This is a seacrowd dataloader for id_vaccines_tweets, for every example in the dataset, it contains a subjective
|
| 44 |
+
tweet and their sentiment polarity. Tweets are from 20-27 June 2021 and 15-22 July 2021."""
|
| 45 |
+
|
| 46 |
+
BUILDER_CONFIGS = [
|
| 47 |
+
SEACrowdConfig(
|
| 48 |
+
name=f"{_DATASETNAME}_source",
|
| 49 |
+
version=datasets.Version(_SOURCE_VERSION),
|
| 50 |
+
description=_DESCRIPTION,
|
| 51 |
+
schema="source",
|
| 52 |
+
subset_id=f"{_DATASETNAME}",
|
| 53 |
+
),
|
| 54 |
+
SEACrowdConfig(
|
| 55 |
+
name=f"{_DATASETNAME}_seacrowd_text",
|
| 56 |
+
version=datasets.Version(_SEACROWD_VERSION),
|
| 57 |
+
description=_DESCRIPTION,
|
| 58 |
+
schema="seacrowd_text",
|
| 59 |
+
subset_id=f"{_DATASETNAME}",
|
| 60 |
+
),
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
| 64 |
+
|
| 65 |
+
def _info(self):
|
| 66 |
+
if self.config.schema == "source":
|
| 67 |
+
features = datasets.Features(
|
| 68 |
+
{
|
| 69 |
+
"idx": datasets.Value("string"),
|
| 70 |
+
"form_text": datasets.Value("string"),
|
| 71 |
+
"norm_text": datasets.Value("string"),
|
| 72 |
+
"subjective": datasets.Value("float"),
|
| 73 |
+
"sentiment": datasets.Value("float"),
|
| 74 |
+
}
|
| 75 |
+
)
|
| 76 |
+
elif self.config.schema == "seacrowd_text":
|
| 77 |
+
features = schemas.text_features([-1.0, 0.0, 1.0])
|
| 78 |
+
else:
|
| 79 |
+
raise ValueError(f"Invalid config: {self.config.name}")
|
| 80 |
+
|
| 81 |
+
return datasets.DatasetInfo(
|
| 82 |
+
description=_DESCRIPTION,
|
| 83 |
+
features=features,
|
| 84 |
+
homepage=_HOMEPAGE,
|
| 85 |
+
license=_LICENSE,
|
| 86 |
+
citation=_CITATION,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
def _split_generators(self, dl_manager):
|
| 90 |
+
""" "return splitGenerators"""
|
| 91 |
+
downloaded_files = dl_manager.download_and_extract(_URL)
|
| 92 |
+
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files})]
|
| 93 |
+
|
| 94 |
+
def _generate_examples(self, filepath):
|
| 95 |
+
data_lines = pandas.read_csv(filepath, skip_blank_lines=True)
|
| 96 |
+
keys = data_lines.keys()
|
| 97 |
+
indexes = data_lines[keys[0]][1:]
|
| 98 |
+
norms = data_lines[keys[1]][1:]
|
| 99 |
+
formals = data_lines[keys[2]][1:]
|
| 100 |
+
subjs = data_lines[keys[3]][1:]
|
| 101 |
+
posnegs = data_lines[keys[4]][1:]
|
| 102 |
+
if self.config.schema == "source":
|
| 103 |
+
for idx, (ind, norm, form, subj, posneg) in enumerate(zip(indexes, norms, formals, subjs, posnegs)):
|
| 104 |
+
yield idx, {
|
| 105 |
+
"idx": str(ind),
|
| 106 |
+
"form_text": form,
|
| 107 |
+
"norm_text": norm,
|
| 108 |
+
"subjective": float(subj),
|
| 109 |
+
"sentiment": float(posneg),
|
| 110 |
+
}
|
| 111 |
+
if self.config.schema == "seacrowd_text":
|
| 112 |
+
for idx, (ind, norm, posneg) in enumerate(zip(indexes, norms, posnegs)):
|
| 113 |
+
yield idx, {"id": str(ind), "text": norm, "label": float(posneg)}
|