"""HateBR dataset""" import datasets import pandas as pd import json _CITATION = """ @inproceedings{vargas2022hatebr, title={HateBR: A Large Expert Annotated Corpus of Brazilian Instagram Comments for Offensive Language and Hate Speech Detection}, author={Vargas, Francielle and Carvalho, Isabelle and de G{\'o}es, Fabiana Rodrigues and Pardo, Thiago and Benevenuto, Fabr{\'\i}cio}, booktitle={Proceedings of the Thirteenth Language Resources and Evaluation Conference}, pages={7174--7183}, year={2022} } """ _DESCRIPTION = """ HateBR is the first large-scale expert annotated corpus of Brazilian Instagram comments for hate speech and offensive language detection on the web and social media. The HateBR corpus was collected from Brazilian Instagram comments of politicians and manually annotated by specialists. It is composed of 7,000 documents annotated according to three different layers: a binary classification (offensive versus non-offensive comments), offensiveness-level (highly, moderately, and slightly offensive messages), and nine hate speech groups (xenophobia, racism, homophobia, sexism, religious intolerance, partyism, apology for the dictatorship, antisemitism, and fatphobia). Each comment was annotated by three different annotators and achieved high inter-annotator agreement. Furthermore, baseline experiments were implemented reaching 85% of F1-score outperforming the current literature models for the Portuguese language. Accordingly, we hope that the proposed expertly annotated corpus may foster research on hate speech and offensive language detection in the Natural Language Processing area. """ _URLS = { "train": "https://raw.githubusercontent.com/franciellevargas/HateBR/2d18c5b9410c2dfdd6d5394caa54d608857dae7c/dataset/HateBR.csv", "annotators": "https://raw.githubusercontent.com/franciellevargas/HateBR/83e8dea4e2d007a08ef534f3322aedeb80949f5c/annotators/final_concordancia_Kappa_Fleiss.csv", "indexes": "https://huggingface.co/datasets/ruanchaves/hatebr/raw/main/indexes.json" } _LABEL_INT_KEY = { "antisemitism": 1, "apology_for_the_dictatorship": 2, "fatphobia": 3, "homophobia": 4, "partyism": 5, "racism": 6, "religious_intolerance": 7, "sexism": 8, "xenophobia": 9, "offensive_&_non-hate_speech": -1, "non-offensive": 0 } _INT_LABEL_KEY = {v:k for k,v in _LABEL_INT_KEY.items()} def process_row(row, annotator_row): categories = row["hate_speech"].split(",") del row["hate_speech"] for default_label in _LABEL_INT_KEY.keys(): row[default_label] = False for int_label in categories: row[_INT_LABEL_KEY[int(int_label)]] = True if isinstance(annotator_row, dict): row["specialist_1_hate_speech"] = bool(int(annotator_row["Avaliador 1"])) row["specialist_2_hate_speech"] = bool(int(annotator_row["Avaliador 2"])) row["specialist_3_hate_speech"] = bool(int(annotator_row["Avaliador 3"])) return row class Boun(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("1.0.0") def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "instagram_comments": datasets.Value("string"), "offensive_language": datasets.Value("bool"), "offensiveness_levels": datasets.Value("int32"), "antisemitism": datasets.Value("bool"), "apology_for_the_dictatorship": datasets.Value("bool"), "fatphobia": datasets.Value("bool"), "homophobia": datasets.Value("bool"), "partyism": datasets.Value("bool"), "racism": datasets.Value("bool"), "religious_intolerance": datasets.Value("bool"), "sexism": datasets.Value("bool"), "xenophobia": datasets.Value("bool"), "offensive_&_non-hate_speech": datasets.Value("bool"), "non-offensive": datasets.Value("bool"), "specialist_1_hate_speech": datasets.Value("bool"), "specialist_2_hate_speech": datasets.Value("bool"), "specialist_3_hate_speech": datasets.Value("bool") }), supervised_keys=None, homepage="https://github.com/franciellevargas/HateBR", citation=_CITATION, ) def _split_generators(self, dl_manager): downloaded_files = dl_manager.download(_URLS) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "filepath": downloaded_files["train"], "annotators": downloaded_files["annotators"], "indexes": downloaded_files["indexes"], "split": "train" } ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "filepath": downloaded_files["train"], "annotators": downloaded_files["annotators"], "indexes": downloaded_files["indexes"], "split": "validation" } ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "filepath": downloaded_files["train"], "annotators": downloaded_files["annotators"], "indexes": downloaded_files["indexes"], "split": "test" } ) ] def _generate_examples(self, filepath, annotators, indexes, split): records = pd.read_csv(filepath).to_dict("records") annotators = pd.read_csv(annotators).to_dict("records") with open(indexes, "r") as f: indexes_object = json.load(f) split_indexes = indexes_object[split] selected_tuples = [] for idx, (row, annotator) in enumerate(zip(records, annotators)): if idx in split_indexes: selected_tuples.append((row, annotator)) processed_records = [ process_row(*args) for args in selected_tuples ] for idx, row in enumerate(processed_records): yield idx, row