Datasets:
Commit
•
e78c445
1
Parent(s):
08fd583
Update bookcorpus.py
Browse files- bookcorpus.py +35 -153
bookcorpus.py
CHANGED
@@ -1,159 +1,41 @@
|
|
1 |
-
|
2 |
-
# Copyright 2023 Your Name or Your Organization
|
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 |
-
# Lint as: python3
|
17 |
-
"""TuPi: Hate Speech Detection Dataset in Portuguese."""
|
18 |
-
|
19 |
-
import os
|
20 |
import pandas as pd
|
21 |
-
import datasets
|
22 |
-
|
23 |
-
_CITATION = """\
|
24 |
-
@article{YourReferenceHere,
|
25 |
-
author = {Your Name or Your Organization},
|
26 |
-
title = {TuPi: Largest Hate Speech Dataset in Portuguese},
|
27 |
-
year = {2023},
|
28 |
-
url = {URL to the official TuPi dataset publication or documentation},
|
29 |
-
eprinttype = {arXiv},
|
30 |
-
timestamp = {Current Timestamp},
|
31 |
-
}
|
32 |
-
"""
|
33 |
-
|
34 |
-
_DESCRIPTION = """\
|
35 |
-
TuPi is the largest annotated dataset for hate speech in Portuguese, formed through the collaboration of Varags et al, Leite et al, and Fortuna et al. The dataset underwent a re-annotation process, including over 10 thousand previously unpublished documents.
|
36 |
-
|
37 |
-
The data includes content from Twitter and Instagram, collected between 2017 and 2023. Each document was individually labeled by three annotators into twelve categories:
|
38 |
-
- Aggressive
|
39 |
-
- Ageism
|
40 |
-
- Aporophobia
|
41 |
-
- Body Shaming
|
42 |
-
- Capacitism
|
43 |
-
- LGBTphobia
|
44 |
-
- Politics
|
45 |
-
- Racism
|
46 |
-
- Religious Intolerance
|
47 |
-
- Misogyny
|
48 |
-
- Xenophobia
|
49 |
-
- Other
|
50 |
-
"""
|
51 |
-
|
52 |
-
_HOMEPAGE = "# Add the TuPi dataset homepage URL"
|
53 |
-
_LICENSE = "# Add the TuPi dataset license URL"
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
"binary": "https://raw.githubusercontent.com/Silly-Machine/TuPi-Portuguese-Hate-Speech-Dataset/main/datasets/tupi_binary.csv",
|
58 |
-
}
|
59 |
-
|
60 |
-
class TuPi(datasets.GeneratorBasedBuilder):
|
61 |
-
"""TuPi Hate Speech Detection Dataset in Portuguese."""
|
62 |
-
|
63 |
-
VERSION = datasets.Version("1.0.0")
|
64 |
-
|
65 |
-
BUILDER_CONFIGS = [
|
66 |
-
datasets.BuilderConfig(
|
67 |
-
name="multilabel",
|
68 |
-
version=VERSION,
|
69 |
-
description="Full multilabel dataset with annotations for each category.",
|
70 |
-
),
|
71 |
-
datasets.BuilderConfig(
|
72 |
-
name="binary",
|
73 |
-
version=VERSION,
|
74 |
-
description="Binary classification dataset with combined hate speech labels.",
|
75 |
-
),
|
76 |
-
]
|
77 |
-
|
78 |
-
DEFAULT_CONFIG_NAME = "binary"
|
79 |
|
80 |
def _info(self):
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
"text": datasets.Value("string"),
|
92 |
-
"aggressive": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
93 |
-
"ageism": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
94 |
-
"aporophobia": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
95 |
-
"body_shaming": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
96 |
-
"capacitism": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
97 |
-
"lgbtphobia": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
98 |
-
"politics": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
99 |
-
"racism": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
100 |
-
"religious_intolerance": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
101 |
-
"misogyny": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
102 |
-
"xenophobia": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
103 |
-
"other": datasets.ClassLabel(names=["zero_votes", "one_vote", "two_votes", "three_votes"]),
|
104 |
-
}
|
105 |
-
)
|
106 |
-
|
107 |
-
return datasets.DatasetInfo(
|
108 |
-
description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION
|
109 |
-
)
|
110 |
|
111 |
def _split_generators(self, dl_manager):
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
),
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
),
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
"filepath": os.path.join(data_dir, "tuipi_multilabel_dataset.csv"),
|
135 |
-
},
|
136 |
-
)
|
137 |
-
]
|
138 |
-
|
139 |
-
def _generate_examples(self, filepath):
|
140 |
-
df = pd.read_csv(filepath, engine="python")
|
141 |
-
for key, row in enumerate(df.itertuples()):
|
142 |
-
if self.config.name == "multilabel":
|
143 |
-
yield key, {
|
144 |
-
"text": row.text,
|
145 |
-
"aggressive": int(float(row.aggressive)),
|
146 |
-
"ageism": int(float(row.ageism)),
|
147 |
-
"aporophobia": int(float(row.aporophobia)),
|
148 |
-
"body_shaming": int(float(row.body_shaming)),
|
149 |
-
"capacitism": int(float(row.capacitism)),
|
150 |
-
"lgbtphobia": int(float(row.lgbtphobia)),
|
151 |
-
"politics": int(float(row.politics)),
|
152 |
-
"racism": int(float(row.racism)),
|
153 |
-
"religious_intolerance": int(float(row.religious_intolerance)),
|
154 |
-
"misogyny": int(float(row.misogyny)),
|
155 |
-
"xenophobia": int(float(row.xenophobia)),
|
156 |
-
"other": int(float(row.other)),
|
157 |
-
}
|
158 |
-
else:
|
159 |
-
yield key, {"text": row.text, "label": int(row.hate)}
|
|
|
1 |
+
from datasets import Dataset, DatasetBuilder
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
class YourDataset(DatasetBuilder):
|
5 |
+
VERSION = "1.0.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def _info(self):
|
8 |
+
features = {
|
9 |
+
"source": "string",
|
10 |
+
"id": "string",
|
11 |
+
"text": "string",
|
12 |
+
"researcher": "string",
|
13 |
+
"year": "int",
|
14 |
+
"aggressive": "float",
|
15 |
+
"hate": "float",
|
16 |
+
}
|
17 |
+
return datasets.DatasetInfo(features=features)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def _split_generators(self, dl_manager):
|
20 |
+
# You can download and extract data here if needed
|
21 |
+
return []
|
22 |
+
|
23 |
+
def _generate_examples(self, file_path):
|
24 |
+
df = pd.read_csv(file_path)
|
25 |
+
for i, row in df.iterrows():
|
26 |
+
yield i, {
|
27 |
+
"source": str(row["source"]),
|
28 |
+
"id": str(row["id"]),
|
29 |
+
"text": str(row["text"]),
|
30 |
+
"researcher": str(row["researcher"]),
|
31 |
+
"year": int(row["year"]),
|
32 |
+
"aggressive": float(row["aggressive"]),
|
33 |
+
"hate": float(row["hate"]),
|
34 |
+
}
|
35 |
+
|
36 |
+
# Load your dataset
|
37 |
+
file_path = "https://raw.githubusercontent.com/Silly-Machine/TuPi-Portuguese-Hate-Speech-Dataset/main/datasets/tupi_binary.csv"
|
38 |
+
your_dataset = Dataset.load_from_disk(file_path)
|
39 |
+
|
40 |
+
# Use the Hugging Face Dataset viewer
|
41 |
+
your_dataset.view()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|