Datasets:
Commit ·
65cc9b4
1
Parent(s): 6db1b6b
Upload korean_hate_speech_copy.py
Browse files- korean_hate_speech_copy.py +114 -0
korean_hate_speech_copy.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 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 |
+
"""K-MHaS Korean Multi-label Hate Speech Dataset"""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import csv
|
| 19 |
+
|
| 20 |
+
import datasets
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_CITATION = """\
|
| 24 |
+
@inproceedings{lee-etal-2022-k,
|
| 25 |
+
title = "K-{MH}a{S}: A Multi-label Hate Speech Detection Dataset in {K}orean Online News Comment",
|
| 26 |
+
author = "Lee, Jean and
|
| 27 |
+
Lim, Taejun and
|
| 28 |
+
Lee, Heejun and
|
| 29 |
+
Jo, Bogeun and
|
| 30 |
+
Kim, Yangsok and
|
| 31 |
+
Yoon, Heegeun and
|
| 32 |
+
Han, Soyeon Caren",
|
| 33 |
+
booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
|
| 34 |
+
month = oct,
|
| 35 |
+
year = "2022",
|
| 36 |
+
address = "Gyeongju, Republic of Korea",
|
| 37 |
+
publisher = "International Committee on Computational Linguistics",
|
| 38 |
+
url = "https://aclanthology.org/2022.coling-1.311",
|
| 39 |
+
pages = "3530--3538",
|
| 40 |
+
abstract = "Online hate speech detection has become an important issue due to the growth of online content, but resources in languages other than English are extremely limited. We introduce K-MHaS, a new multi-label dataset for hate speech detection that effectively handles Korean language patterns. The dataset consists of 109k utterances from news comments and provides a multi-label classification using 1 to 4 labels, and handles subjectivity and intersectionality. We evaluate strong baselines on K-MHaS. KR-BERT with a sub-character tokenizer outperforms others, recognizing decomposed characters in each hate speech class.",
|
| 41 |
+
}
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
_DESCRIPTION = """\
|
| 45 |
+
The K-MHaS (Korean Multi-label Hate Speech) dataset contains 109k utterances from Korean online news comments labeled with 8 fine-grained hate speech classes or Not Hate Speech class.
|
| 46 |
+
The fine-grained hate speech classes are politics, origin, physical, age, gender, religion, race, and profanity and these categories are selected in order to reflect the social and historical context.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
_HOMEPAGE = "https://github.com/adlnlp/K-MHaS"
|
| 50 |
+
|
| 51 |
+
_LICENSE = "cc-by-sa-4.0"
|
| 52 |
+
|
| 53 |
+
_TRAIN_DOWNLOAD_URL = "https://raw.githubusercontent.com/adlnlp/K-MHaS/main/data/kmhas_train.txt"
|
| 54 |
+
_VALIDATION_DOWNLOAD_URL = "https://raw.githubusercontent.com/adlnlp/K-MHaS/main/data/kmhas_valid.txt"
|
| 55 |
+
_TEST_DOWNLOAD_URL = "https://raw.githubusercontent.com/adlnlp/K-MHaS/main/data/kmhas_test.txt"
|
| 56 |
+
|
| 57 |
+
_CLASS_NAMES = [
|
| 58 |
+
"origin",
|
| 59 |
+
"physical",
|
| 60 |
+
"politics",
|
| 61 |
+
"profanity",
|
| 62 |
+
"age",
|
| 63 |
+
"gender",
|
| 64 |
+
"race",
|
| 65 |
+
"religion",
|
| 66 |
+
"not_hate_speech"
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
class Kmhas(datasets.GeneratorBasedBuilder):
|
| 70 |
+
"""K-MHaS Korean Multi-label Hate Speech Dataset"""
|
| 71 |
+
|
| 72 |
+
VERSION = datasets.Version("1.0.0")
|
| 73 |
+
|
| 74 |
+
def _info(self):
|
| 75 |
+
features = datasets.Features(
|
| 76 |
+
{
|
| 77 |
+
"text": datasets.Value("string"),
|
| 78 |
+
"label": datasets.Sequence(datasets.ClassLabel(names=_CLASS_NAMES))
|
| 79 |
+
}
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
return datasets.DatasetInfo(
|
| 83 |
+
description=_DESCRIPTION,
|
| 84 |
+
features=features,
|
| 85 |
+
homepage=_HOMEPAGE,
|
| 86 |
+
license=_LICENSE,
|
| 87 |
+
citation=_CITATION,
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
def _split_generators(self, dl_manager):
|
| 91 |
+
train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
|
| 92 |
+
validation_path = dl_manager.download_and_extract(_VALIDATION_DOWNLOAD_URL)
|
| 93 |
+
test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
|
| 94 |
+
return [
|
| 95 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}),
|
| 96 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": validation_path}),
|
| 97 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
def _generate_examples(self, filepath):
|
| 101 |
+
"""Generate K-MHaS Korean Multi-label Hate Speech examples"""
|
| 102 |
+
|
| 103 |
+
with open(filepath, 'r', encoding="utf-8") as f:
|
| 104 |
+
lines = f.readlines()[1:]
|
| 105 |
+
|
| 106 |
+
for index, line in enumerate(lines):
|
| 107 |
+
row = line.strip().split('\t')
|
| 108 |
+
sentence = row[0]
|
| 109 |
+
label = [int(ind) for ind in row[1].split(",")]
|
| 110 |
+
yield index, {
|
| 111 |
+
"text" : sentence,
|
| 112 |
+
"label": label,
|
| 113 |
+
}
|
| 114 |
+
|