SEACrowd/id_multilabel_hs
The ID_MULTILABEL_HS dataset is collection of 13,169 tweets in Indonesian language, designed for hate speech detection NLP task. This dataset is combination from previous research and newly crawled data from Twitter. This is a multilabel dataset with label details as follows: -HS : hate speech label; -Abusive : abusive language label; -HS_Individual : hate speech targeted to an individual; -HS_Group : hate speech targeted to a group; -HS_Religion : hate speech related to religion/creed; -HS_Race : hate speech related to race/ethnicity; -HS_Physical : hate speech related to physical/disability; -HS_Gender : hate speech related to gender/sexual orientation; -HS_Gender : hate related to other invective/slander; -HS_Weak : weak hate speech; -HS_Moderate : moderate hate speech; -HS_Strong : strong hate speech.
1from pathlib import Path2from typing import Dict, List, Tuple3 4import datasets5import pandas as pd6 7from seacrowd.utils import schemas8from seacrowd.utils.configs import SEACrowdConfig9from seacrowd.utils.constants import Tasks10 11_CITATION = """\12@inproceedings{ibrohim-budi-2019-multi,13 title = "Multi-label Hate Speech and Abusive Language Detection in {I}ndonesian {T}witter",14 author = "Ibrohim, Muhammad Okky and15 Budi, Indra",16 booktitle = "Proceedings of the Third Workshop on Abusive Language Online",17 month = aug,18 year = "2019",19 address = "Florence, Italy",20 publisher = "Association for Computational Linguistics",21 url = "https://aclanthology.org/W19-3506",22 doi = "10.18653/v1/W19-3506",23 pages = "46--57",24}25"""26 27_LOCAL = False28_LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)29_DATASETNAME = "id_multilabel_hs"30 31_DESCRIPTION = """\32The ID_MULTILABEL_HS dataset is collection of 13,169 tweets in Indonesian language,33designed for hate speech detection NLP task. This dataset is combination from previous research and newly crawled data from Twitter.34This is a multilabel dataset with label details as follows:35-HS : hate speech label;36-Abusive : abusive language label;37-HS_Individual : hate speech targeted to an individual;38-HS_Group : hate speech targeted to a group;39-HS_Religion : hate speech related to religion/creed;40-HS_Race : hate speech related to race/ethnicity;41-HS_Physical : hate speech related to physical/disability;42-HS_Gender : hate speech related to gender/sexual orientation;43-HS_Gender : hate related to other invective/slander;44-HS_Weak : weak hate speech;45-HS_Moderate : moderate hate speech;46-HS_Strong : strong hate speech.47"""48 49_HOMEPAGE = "https://aclanthology.org/W19-3506/"50_LICENSE = "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"51_URLS = {52 _DATASETNAME: "https://raw.githubusercontent.com/okkyibrohim/id-multi-label-hate-speech-and-abusive-language-detection/master/re_dataset.csv",53}54_SUPPORTED_TASKS = [Tasks.ASPECT_BASED_SENTIMENT_ANALYSIS]55_SOURCE_VERSION = "1.0.0"56_SEACROWD_VERSION = "2024.06.20"57 58 59class IdAbusive(datasets.GeneratorBasedBuilder):60 """The ID_MULTILABEL_HS dataset is multi-label hate speech and abusive language detection in Indonesian tweets"""61 62 SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)63 SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)64 65 BUILDER_CONFIGS = [66 SEACrowdConfig(67 name="id_multilabel_hs_source",68 version=SOURCE_VERSION,69 description="ID Multilabel HS source schema",70 schema="source",71 subset_id="id_multilabel_hs",72 ),73 SEACrowdConfig(74 name="id_multilabel_hs_seacrowd_text_multi",75 version=SEACROWD_VERSION,76 description="ID Multilabel HS Nusantara schema",77 schema="seacrowd_text_multi",78 subset_id="id_multilabel_hs",79 ),80 ]81 82 DEFAULT_CONFIG_NAME = "id_multilabel_hs_source"83 84 def _info(self) -> datasets.DatasetInfo:85 if self.config.schema == "source":86 features = datasets.Features({87 "tweet": datasets.Value("string"), 88 "HS": datasets.Value("bool"),89 "Abusive": datasets.Value("bool"), 90 "HS_Individual": datasets.Value("bool"), 91 "HS_Group": datasets.Value("bool"), 92 "HS_Religion": datasets.Value("bool"), 93 "HS_Race": datasets.Value("bool"), 94 "HS_Physical": datasets.Value("bool"), 95 "HS_Gender": datasets.Value("bool"), 96 "HS_Other": datasets.Value("bool"), 97 "HS_Weak": datasets.Value("bool"), 98 "HS_Moderate": datasets.Value("bool"), 99 "HS_Strong": datasets.Value("bool"),100 })101 elif self.config.schema == "seacrowd_text_multi":102 features = schemas.text_multi_features([0, 1])103 104 return datasets.DatasetInfo(105 description=_DESCRIPTION,106 features=features,107 homepage=_HOMEPAGE,108 license=_LICENSE,109 citation=_CITATION,110 )111 112 def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:113 """Returns SplitGenerators."""114 # Dataset does not have predetermined split, putting all as TRAIN115 urls = _URLS[_DATASETNAME]116 base_dir = Path(dl_manager.download_and_extract(urls))117 data_files = {"train": base_dir}118 119 return [120 datasets.SplitGenerator(121 name=datasets.Split.TRAIN,122 gen_kwargs={123 "filepath": data_files["train"],124 "split": "train",125 },126 ),127 ]128 129 def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:130 """Yields examples as (key, example) tuples."""131 # Dataset does not have id, using row index as id132 label_cols = ["HS", "Abusive", "HS_Individual", "HS_Group", "HS_Religion", "HS_Race", "HS_Physical", "HS_Gender", "HS_Other", "HS_Weak", "HS_Moderate", "HS_Strong"]133 df = pd.read_csv(filepath, encoding="ISO-8859-1").reset_index()134 df.columns = ["id", "tweet"] + label_cols135 136 if self.config.schema == "source":137 for row in df.itertuples():138 ex = {139 "tweet": row.tweet,140 }141 for label in label_cols:142 ex[label] = getattr(row, label)143 yield row.id, ex144 145 elif self.config.schema == "seacrowd_text_multi":146 for row in df.itertuples():147 ex = {148 "id": str(row.id),149 "text": row.tweet,150 "labels": [label for label in row[3:]],151 }152 yield row.id, ex153 else:154 raise ValueError(f"Invalid config: {self.config.name}")155 