holylovenia commited on
Commit
1c81d66
1 Parent(s): 08ae0ad

Upload id_abusive_news_comment.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. id_abusive_news_comment.py +108 -0
id_abusive_news_comment.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+ import datasets
5
+ import pandas as pd
6
+
7
+ from nusacrowd.utils import schemas
8
+ from nusacrowd.utils.configs import NusantaraConfig
9
+ from nusacrowd.utils.constants import DEFAULT_NUSANTARA_VIEW_NAME, DEFAULT_SOURCE_VIEW_NAME, Tasks
10
+
11
+ _DATASETNAME = "id_abusive_news_comment"
12
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
13
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
14
+
15
+ _LANGUAGES = ["ind"] # We follow ISO639-3 langauge code (https://iso639-3.sil.org/code_tables/639/data)
16
+ _LOCAL = False
17
+ _CITATION = """\
18
+ @INPROCEEDINGS{9034620, author={Kiasati Desrul, Dhamir Raniah and Romadhony, Ade}, booktitle={2019 International Seminar on Research of Information Technology and Intelligent Systems (ISRITI)}, title={Abusive Language Detection on Indonesian Online News Comments}, year={2019}, volume={}, number={}, pages={320-325}, doi={10.1109/ISRITI48646.2019.9034620}}
19
+ """
20
+
21
+ _DESCRIPTION = """\
22
+ Abusive language is an expression used by a person with insulting delivery of any person's aspect.
23
+ In the modern era, the use of harsh words is often found on the internet, one of them is in the comment section of online news articles which contains harassment, insult, or a curse.
24
+ An abusive language detection system is important to prevent the negative effect of such comments.
25
+ This dataset contains 3184 samples of Indonesian online news comments with 3 labels.
26
+ """
27
+
28
+ _HOMEPAGE = "https://github.com/dhamirdesrul/Indonesian-Online-News-Comments"
29
+
30
+ _LICENSE = "Creative Commons Attribution Share-Alike 4.0 International"
31
+
32
+ _URLs = {
33
+ "train": "https://github.com/dhamirdesrul/Indonesian-Online-News-Comments/raw/master/Dataset/Abusive%20Language%20Detection%20on%20Indonesian%20Online%20News%20Comments%20Dataset%20.xlsx",
34
+ }
35
+
36
+ _SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
37
+
38
+ _SOURCE_VERSION = "1.0.0"
39
+ _NUSANTARA_VERSION = "1.0.0"
40
+
41
+
42
+ class IdAbusiveNewsComment(datasets.GeneratorBasedBuilder):
43
+
44
+ BUILDER_CONFIGS = [
45
+ NusantaraConfig(
46
+ name="id_abusive_news_comment_source",
47
+ version=datasets.Version(_SOURCE_VERSION),
48
+ description="Abusive Online News Comment source schema",
49
+ schema="source",
50
+ subset_id="id_abusive_news_comment",
51
+ ),
52
+ NusantaraConfig(
53
+ name="id_abusive_news_comment_nusantara_text",
54
+ version=datasets.Version(_NUSANTARA_VERSION),
55
+ description="Abusive Online News Comment Nusantara schema",
56
+ schema="nusantara_text",
57
+ subset_id="id_abusive_news_comment",
58
+ ),
59
+ ]
60
+
61
+ DEFAULT_CONFIG_NAME = "id_abusive_news_comment"
62
+
63
+ def _info(self):
64
+ if self.config.schema == "source":
65
+ features = datasets.Features(
66
+ {
67
+ "index": datasets.Value("string"),
68
+ "text": datasets.Value("string"),
69
+ "label": datasets.Value("string"),
70
+ }
71
+ )
72
+ elif self.config.schema == "nusantara_text":
73
+ features = schemas.text_features(['1', '2', '3'])
74
+
75
+ return datasets.DatasetInfo(
76
+ description=_DESCRIPTION,
77
+ features=features,
78
+ homepage=_HOMEPAGE,
79
+ license=_LICENSE,
80
+ citation=_CITATION,
81
+ )
82
+
83
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
84
+ train_tsv_path = Path(dl_manager.download(_URLs["train"]))
85
+ data_files = {
86
+ "train": train_tsv_path,
87
+ }
88
+
89
+ return [
90
+ datasets.SplitGenerator(
91
+ name=datasets.Split.TRAIN,
92
+ gen_kwargs={"filepath": data_files["train"]},
93
+ ),
94
+ ]
95
+
96
+ def _generate_examples(self, filepath: Path):
97
+ df = pd.read_excel(filepath).reset_index()
98
+
99
+ if self.config.schema == "source":
100
+ for row in df.itertuples():
101
+ ex = {"index": str(row.index), "text": row.Kalimat, "label": str(row.label)}
102
+ yield row.index, ex
103
+ elif self.config.schema == "nusantara_text":
104
+ for row in df.itertuples():
105
+ ex = {"id": str(row.index), "text": row.Kalimat, "label": str(row.label)}
106
+ yield row.index, ex
107
+ else:
108
+ raise ValueError(f"Invalid config: {self.config.name}")