Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
sentiment-classification
Languages:
English
Size:
10K - 100K
License:
Commit
•
a642fa4
1
Parent(s):
c077341
Delete loading script
Browse files
tweets_hate_speech_detection.py
DELETED
@@ -1,83 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
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 |
-
"""Detecing which tweets showcase hate or racist remarks."""
|
18 |
-
|
19 |
-
|
20 |
-
import csv
|
21 |
-
|
22 |
-
import datasets
|
23 |
-
from datasets.tasks import TextClassification
|
24 |
-
|
25 |
-
|
26 |
-
_DESCRIPTION = """\
|
27 |
-
The objective of this task is to detect hate speech in tweets. For the sake of simplicity, we say a tweet contains hate speech if it has a racist or sexist sentiment associated with it. So, the task is to classify racist or sexist tweets from other tweets.
|
28 |
-
|
29 |
-
Formally, given a training sample of tweets and labels, where label ‘1’ denotes the tweet is racist/sexist and label ‘0’ denotes the tweet is not racist/sexist, your objective is to predict the labels on the given test dataset.
|
30 |
-
"""
|
31 |
-
|
32 |
-
_HOMEPAGE = "https://github.com/sharmaroshan/Twitter-Sentiment-Analysis"
|
33 |
-
|
34 |
-
_CITATION = """\
|
35 |
-
@InProceedings{Z
|
36 |
-
Roshan Sharma:dataset,
|
37 |
-
title = {Sentimental Analysis of Tweets for Detecting Hate/Racist Speeches},
|
38 |
-
authors={Roshan Sharma},
|
39 |
-
year={2018}
|
40 |
-
}
|
41 |
-
"""
|
42 |
-
|
43 |
-
_URL = {
|
44 |
-
"train": "https://raw.githubusercontent.com/sharmaroshan/Twitter-Sentiment-Analysis/master/train_tweet.csv",
|
45 |
-
"test": "https://raw.githubusercontent.com/sharmaroshan/Twitter-Sentiment-Analysis/master/test_tweets.csv",
|
46 |
-
}
|
47 |
-
|
48 |
-
|
49 |
-
class TweetsHateSpeechDetection(datasets.GeneratorBasedBuilder):
|
50 |
-
"""Detecting which tweets showcase hate or racist remarks."""
|
51 |
-
|
52 |
-
def _info(self):
|
53 |
-
return datasets.DatasetInfo(
|
54 |
-
description=_DESCRIPTION,
|
55 |
-
features=datasets.Features(
|
56 |
-
{
|
57 |
-
"label": datasets.ClassLabel(names=["no-hate-speech", "hate-speech"]),
|
58 |
-
"tweet": datasets.Value("string"),
|
59 |
-
}
|
60 |
-
),
|
61 |
-
homepage=_HOMEPAGE,
|
62 |
-
citation=_CITATION,
|
63 |
-
task_templates=[TextClassification(text_column="tweet", label_column="label")],
|
64 |
-
)
|
65 |
-
|
66 |
-
def _split_generators(self, dl_manager):
|
67 |
-
path = dl_manager.download(_URL)
|
68 |
-
return [
|
69 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": path["train"]}),
|
70 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": path["test"]}),
|
71 |
-
]
|
72 |
-
|
73 |
-
def _generate_examples(self, filepath):
|
74 |
-
"""Generate Tweet examples."""
|
75 |
-
with open(filepath, encoding="utf-8") as csv_file:
|
76 |
-
csv_reader = csv.DictReader(
|
77 |
-
csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
|
78 |
-
)
|
79 |
-
for id_, row in enumerate(csv_reader):
|
80 |
-
yield id_, {
|
81 |
-
"label": int(row.setdefault("label", -1)),
|
82 |
-
"tweet": row["tweet"],
|
83 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|