Add data
Browse files- dataset_infos.json +1 -0
- ethos.py +159 -0
dataset_infos.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"binary": {"description": "", "citation": "\n@misc{mollas2020ethos,\n title={ETHOS: an Online Hate Speech Detection Dataset},\n author={Ioannis Mollas and Zoe Chrysopoulou and Stamatis Karlos and Grigorios Tsoumakas},\n year={2020},\n eprint={2006.08328},\n archivePrefix={arXiv},\n primaryClass={cs.CL}\n}\n ", "homepage": "https://github.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset/tree/masterethos/ethos_data", "license": "", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"num_classes": 2, "names": ["no_hate_speech", "hate_speech"], "names_file": null, "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "ethos", "config_name": "binary", "version": {"version_str": "1.0.0", "description": "", "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 124823, "num_examples": 998, "dataset_name": "ethos"}}, "download_checksums": {"https://raw.githubusercontent.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset/master/ethos/ethos_data/Ethos_Dataset_Binary.csv": {"num_bytes": 123919, "checksum": "0cd0050c2592afcb5eca5876df485ca15cda9d7d16fe32c269857260fd10d96c"}}, "download_size": 123919, "post_processing_size": null, "dataset_size": 124823, "size_in_bytes": 248742}, "multilabel": {"description": "", "citation": "\n@misc{mollas2020ethos,\n title={ETHOS: an Online Hate Speech Detection Dataset},\n author={Ioannis Mollas and Zoe Chrysopoulou and Stamatis Karlos and Grigorios Tsoumakas},\n year={2020},\n eprint={2006.08328},\n archivePrefix={arXiv},\n primaryClass={cs.CL}\n}\n ", "homepage": "https://github.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset/tree/masterethos/ethos_data", "license": "", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "violence": {"num_classes": 2, "names": ["not_violent", "violent"], "names_file": null, "id": null, "_type": "ClassLabel"}, "directed_vs_generalized": {"num_classes": 2, "names": ["generalied", "directed"], "names_file": null, "id": null, "_type": "ClassLabel"}, "gender": {"num_classes": 2, "names": ["false", "true"], "names_file": null, "id": null, "_type": "ClassLabel"}, "race": {"num_classes": 2, "names": ["false", "true"], "names_file": null, "id": null, "_type": "ClassLabel"}, "national_origin": {"num_classes": 2, "names": ["false", "true"], "names_file": null, "id": null, "_type": "ClassLabel"}, "disability": {"num_classes": 2, "names": ["false", "true"], "names_file": null, "id": null, "_type": "ClassLabel"}, "religion": {"num_classes": 2, "names": ["false", "true"], "names_file": null, "id": null, "_type": "ClassLabel"}, "sexual_orientation": {"num_classes": 2, "names": ["false", "true"], "names_file": null, "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "ethos", "config_name": "multilabel", "version": {"version_str": "1.0.0", "description": "", "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 79112, "num_examples": 433, "dataset_name": "ethos"}}, "download_checksums": {"https://raw.githubusercontent.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset/master/ethos/ethos_data/Ethos_Dataset_Multi_Label.csv": {"num_bytes": 62836, "checksum": "488c72a1582abdaf489a6e9eceeebba505447a00a25bd02e72fd6a56f9a3d83d"}}, "download_size": 62836, "post_processing_size": null, "dataset_size": 79112, "size_in_bytes": 141948}}
|
ethos.py
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Ethos dataset"""
|
2 |
+
|
3 |
+
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
import datasets
|
7 |
+
|
8 |
+
|
9 |
+
logger = datasets.logging.get_logger(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
_CITATION = """
|
13 |
+
@misc{mollas2020ethos,
|
14 |
+
title={ETHOS: an Online Hate Speech Detection Dataset},
|
15 |
+
author={Ioannis Mollas and Zoe Chrysopoulou and Stamatis Karlos and Grigorios Tsoumakas},
|
16 |
+
year={2020},
|
17 |
+
eprint={2006.08328},
|
18 |
+
archivePrefix={arXiv},
|
19 |
+
primaryClass={cs.CL}
|
20 |
+
}
|
21 |
+
"""
|
22 |
+
|
23 |
+
_DESCRIPTION = """
|
24 |
+
|
25 |
+
ETHOS: onlinE haTe speecH detectiOn dataSet. This repository contains a dataset for hate speech
|
26 |
+
detection on social media platforms, called Ethos. There are two variations of the dataset:
|
27 |
+
|
28 |
+
Ethos_Dataset_Binary: contains 998 comments in the dataset alongside with a label
|
29 |
+
about hate speech presence or absence. 565 of them do not contain hate speech,
|
30 |
+
while the rest of them, 433, contain.
|
31 |
+
|
32 |
+
Ethos_Dataset_Multi_Label: which contains 8 labels for the 433 comments with hate speech content.
|
33 |
+
These labels are violence (if it incites (1) or not (0) violence), directed_vs_general (if it is
|
34 |
+
directed to a person (1) or a group (0)), and 6 labels about the category of hate speech like,
|
35 |
+
gender, race, national_origin, disability, religion and sexual_orientation.
|
36 |
+
"""
|
37 |
+
|
38 |
+
_URL = "https://github.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset"
|
39 |
+
|
40 |
+
|
41 |
+
class EthosConfig(datasets.BuilderConfig):
|
42 |
+
"""BuilderConfig for Ethos."""
|
43 |
+
|
44 |
+
def __init__(self, variation="binary", **kwargs):
|
45 |
+
"""Constructs an EthosDataset.
|
46 |
+
|
47 |
+
Args:
|
48 |
+
variation: can be binary or multilabel
|
49 |
+
**kwargs: keyword arguments forwarded to super.
|
50 |
+
"""
|
51 |
+
if variation.lower() == "binary":
|
52 |
+
self.variation = "binary"
|
53 |
+
elif variation.lower() == "multilabel":
|
54 |
+
self.variation = "multilabel"
|
55 |
+
else:
|
56 |
+
logger.warning("Wrong variation. Could be either 'binary' or 'multilabel', using 'binary' instead.")
|
57 |
+
self.variation = "binary"
|
58 |
+
super(EthosConfig, self).__init__(**kwargs)
|
59 |
+
|
60 |
+
|
61 |
+
class Ethos(datasets.GeneratorBasedBuilder):
|
62 |
+
BUILDER_CONFIG_CLASS = EthosConfig
|
63 |
+
|
64 |
+
BUILDER_CONFIGS = [
|
65 |
+
EthosConfig(
|
66 |
+
name="binary",
|
67 |
+
version=datasets.Version("1.0.0", ""),
|
68 |
+
description="Ethos Binary",
|
69 |
+
variation="binary",
|
70 |
+
),
|
71 |
+
EthosConfig(
|
72 |
+
name="multilabel",
|
73 |
+
version=datasets.Version("1.0.0", ""),
|
74 |
+
description="Ethos Multi Label",
|
75 |
+
variation="multilabel",
|
76 |
+
),
|
77 |
+
]
|
78 |
+
|
79 |
+
def _info(self):
|
80 |
+
if self.config.variation == "binary":
|
81 |
+
f = datasets.Features(
|
82 |
+
{
|
83 |
+
"text": datasets.Value("string"),
|
84 |
+
"label": datasets.features.ClassLabel(names=["no_hate_speech", "hate_speech"]),
|
85 |
+
}
|
86 |
+
)
|
87 |
+
else:
|
88 |
+
f = datasets.Features(
|
89 |
+
{
|
90 |
+
"text": datasets.Value("string"),
|
91 |
+
"violence": datasets.ClassLabel(names=["not_violent", "violent"]),
|
92 |
+
"directed_vs_generalized": datasets.ClassLabel(names=["generalied", "directed"]),
|
93 |
+
"gender": datasets.ClassLabel(names=["false", "true"]),
|
94 |
+
"race": datasets.ClassLabel(names=["false", "true"]),
|
95 |
+
"national_origin": datasets.ClassLabel(names=["false", "true"]),
|
96 |
+
"disability": datasets.ClassLabel(names=["false", "true"]),
|
97 |
+
"religion": datasets.ClassLabel(names=["false", "true"]),
|
98 |
+
"sexual_orientation": datasets.ClassLabel(names=["false", "true"]),
|
99 |
+
}
|
100 |
+
)
|
101 |
+
return datasets.DatasetInfo(
|
102 |
+
features=f,
|
103 |
+
supervised_keys=None,
|
104 |
+
homepage="https://github.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset/tree/masterethos/ethos_data",
|
105 |
+
citation=_CITATION,
|
106 |
+
)
|
107 |
+
|
108 |
+
def _split_generators(self, dl_manager):
|
109 |
+
if self.config.variation == "binary":
|
110 |
+
url = {
|
111 |
+
"train": "https://raw.githubusercontent.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset"
|
112 |
+
"/master/ethos/ethos_data/Ethos_Dataset_Binary.csv"
|
113 |
+
}
|
114 |
+
else:
|
115 |
+
url = {
|
116 |
+
"train": "https://raw.githubusercontent.com/intelligence-csd-auth-gr/Ethos-Hate-Speech-Dataset"
|
117 |
+
"/master/ethos/ethos_data/Ethos_Dataset_Multi_Label.csv"
|
118 |
+
}
|
119 |
+
downloaded_files = dl_manager.download_and_extract(url)
|
120 |
+
|
121 |
+
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]})]
|
122 |
+
|
123 |
+
def _generate_examples(self, filepath):
|
124 |
+
"""Yields examples."""
|
125 |
+
|
126 |
+
data = pd.read_csv(filepath, delimiter=";")
|
127 |
+
if self.config.variation == "binary":
|
128 |
+
|
129 |
+
x = data["comment"].values
|
130 |
+
y = [1 if i >= 0.5 else 0 for i in data["isHate"].values]
|
131 |
+
class_names = ["no_hate_speech", "hate_speech"]
|
132 |
+
for i in range(len(x)):
|
133 |
+
_id = i
|
134 |
+
yield _id, {"text": x[i], "label": class_names[y[i]]}
|
135 |
+
else:
|
136 |
+
x = data["comment"].values
|
137 |
+
y_temp = data.loc[:, data.columns != "comment"].values
|
138 |
+
y = []
|
139 |
+
for yt in y_temp:
|
140 |
+
yi = []
|
141 |
+
for i in yt:
|
142 |
+
if i >= 0.5:
|
143 |
+
yi.append(int(1))
|
144 |
+
else:
|
145 |
+
yi.append(int(0))
|
146 |
+
y.append(yi)
|
147 |
+
for i in range(len(x)):
|
148 |
+
_id = i
|
149 |
+
yield _id, {
|
150 |
+
"text": x[i],
|
151 |
+
"violence": y[i][0],
|
152 |
+
"directed_vs_generalized": y[i][1],
|
153 |
+
"gender": y[i][2],
|
154 |
+
"race": y[i][3],
|
155 |
+
"national_origin": y[i][4],
|
156 |
+
"disability": y[i][5],
|
157 |
+
"religion": y[i][6],
|
158 |
+
"sexual_orientation": y[i][7],
|
159 |
+
}
|