holylovenia commited on
Commit
f05cb89
1 Parent(s): dc4a743

Upload id_clickbait.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. id_clickbait.py +125 -0
id_clickbait.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Dict, List, Tuple
4
+
5
+ import datasets
6
+
7
+ from nusacrowd.utils import schemas
8
+ from nusacrowd.utils.configs import NusantaraConfig
9
+ from nusacrowd.utils.constants import Tasks
10
+
11
+ _CITATION = """\
12
+ @article{WILLIAM2020106231,
13
+ title = "CLICK-ID: A novel dataset for Indonesian clickbait headlines",
14
+ journal = "Data in Brief",
15
+ volume = "32",
16
+ pages = "106231",
17
+ year = "2020",
18
+ issn = "2352-3409",
19
+ doi = "https://doi.org/10.1016/j.dib.2020.106231",
20
+ url = "http://www.sciencedirect.com/science/article/pii/S2352340920311252",
21
+ author = "Andika William and Yunita Sari",
22
+ keywords = "Indonesian, Natural Language Processing, News articles, Clickbait, Text-classification",
23
+ abstract = "News analysis is a popular task in Natural Language Processing (NLP). In particular, the problem of clickbait in news analysis has gained attention in recent years [1, 2]. However, the majority of the tasks has been focused on English news, in which there is already a rich representative resource. For other languages, such as Indonesian, there is still a lack of resource for clickbait tasks. Therefore, we introduce the CLICK-ID dataset of Indonesian news headlines extracted from 12 Indonesian online news publishers. It is comprised of 15,000 annotated headlines with clickbait and non-clickbait labels. Using the CLICK-ID dataset, we then developed an Indonesian clickbait classification model achieving favourable performance. We believe that this corpus will be useful for replicable experiments in clickbait detection or other experiments in NLP areas."
24
+ }
25
+ """
26
+
27
+ _LOCAL = False
28
+ _LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
29
+ _DATASETNAME = "id_clickbait"
30
+ _DESCRIPTION = """\
31
+ The CLICK-ID dataset is a collection of Indonesian news headlines that was collected from 12 local online news
32
+ publishers; detikNews, Fimela, Kapanlagi, Kompas, Liputan6, Okezone, Posmetro-Medan, Republika, Sindonews, Tempo,
33
+ Tribunnews, and Wowkeren. This dataset is comprised of mainly two parts; (i) 46,119 raw article data, and (ii)
34
+ 15,000 clickbait annotated sample headlines. Annotation was conducted with 3 annotator examining each headline.
35
+ Judgment were based only on the headline. The majority then is considered as the ground truth. In the annotated
36
+ sample, our annotation shows 6,290 clickbait and 8,710 non-clickbait.
37
+ """
38
+ _HOMEPAGE = "https://www.sciencedirect.com/science/article/pii/S2352340920311252#!"
39
+ _LICENSE = "Creative Commons Attribution 4.0 International"
40
+ _URLS = {
41
+ _DATASETNAME: "https://prod-dcd-datasets-cache-zipfiles.s3.eu-west-1.amazonaws.com/k42j7x2kpn-1.zip",
42
+ }
43
+ _SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
44
+ _SOURCE_VERSION = "1.0.0"
45
+ _NUSANTARA_VERSION = "1.0.0"
46
+
47
+
48
+ class IdClickbait(datasets.GeneratorBasedBuilder):
49
+ """The CLICK-ID dataset is a collection of Indonesian news headlines that was collected from 12 local online news, annotated with a label whether each is a clickbait"""
50
+
51
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
52
+ NUSANTARA_VERSION = datasets.Version(_NUSANTARA_VERSION)
53
+
54
+ BUILDER_CONFIGS = [
55
+ NusantaraConfig(
56
+ name="id_clickbait_source",
57
+ version=SOURCE_VERSION,
58
+ description="CLICK-ID source schema",
59
+ schema="source",
60
+ subset_id="id_clickbait",
61
+ ),
62
+ NusantaraConfig(
63
+ name="id_clickbait_nusantara_text",
64
+ version=NUSANTARA_VERSION,
65
+ description="CLICK-ID Nusantara schema",
66
+ schema="nusantara_text",
67
+ subset_id="id_clickbait",
68
+ ),
69
+ ]
70
+
71
+ DEFAULT_CONFIG_NAME = "id_clickbait_source"
72
+
73
+ def _info(self) -> datasets.DatasetInfo:
74
+ if self.config.schema == "source":
75
+ features = datasets.Features({"title": datasets.Value("string"), "label": datasets.Value("string"), "label_score": datasets.Value("int8")})
76
+ elif self.config.schema == "nusantara_text":
77
+ features = schemas.text_features(["non-clickbait", "clickbait"])
78
+
79
+ return datasets.DatasetInfo(
80
+ description=_DESCRIPTION,
81
+ features=features,
82
+ homepage=_HOMEPAGE,
83
+ license=_LICENSE,
84
+ citation=_CITATION,
85
+ )
86
+
87
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
88
+ """Returns SplitGenerators."""
89
+ # Dataset does not have predetermined split, putting all as TRAIN
90
+ urls = _URLS[_DATASETNAME]
91
+ base_dir = Path(dl_manager.download_and_extract(urls)) / "annotated" / "combined" / "json"
92
+ data_files = {"train": base_dir / "main.json"}
93
+
94
+ return [
95
+ datasets.SplitGenerator(
96
+ name=datasets.Split.TRAIN,
97
+ gen_kwargs={
98
+ "filepath": data_files["train"],
99
+ "split": "train",
100
+ },
101
+ ),
102
+ ]
103
+
104
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
105
+ """Yields examples as (key, example) tuples."""
106
+ # Dataset does not have row id, using python enumeration.
107
+ data = json.load(open(filepath, "r"))
108
+
109
+ if self.config.schema == "source":
110
+ for row_index, row in enumerate(data):
111
+ ex = {
112
+ "title": row["title"],
113
+ "label": row["label"],
114
+ "label_score": row["label_score"],
115
+ }
116
+ yield row_index, ex
117
+
118
+ elif self.config.schema == "nusantara_text":
119
+ for row_index, row in enumerate(data):
120
+ ex = {
121
+ "id": str(row_index),
122
+ "text": row["title"],
123
+ "label": row["label"],
124
+ }
125
+ yield row_index, ex