holylovenia
commited on
Commit
•
a4796f6
1
Parent(s):
116ab8f
Upload fakenews_ph.py with huggingface_hub
Browse files- fakenews_ph.py +138 -0
fakenews_ph.py
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
from pathlib import Path
|
3 |
+
from typing import Dict, List, Tuple
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
from datasets.download.download_manager import DownloadManager
|
7 |
+
|
8 |
+
from seacrowd.utils import schemas
|
9 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
10 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
11 |
+
|
12 |
+
_CITATION = r"""
|
13 |
+
@inproceedings{cruz-etal-2020-localization,
|
14 |
+
title = "Localization of Fake News Detection via Multitask Transfer Learning",
|
15 |
+
author = "Cruz, Jan Christian Blaise and
|
16 |
+
Tan, Julianne Agatha and
|
17 |
+
Cheng, Charibeth",
|
18 |
+
editor = "Calzolari, Nicoletta and
|
19 |
+
B{\'e}chet, Fr{\'e}d{\'e}ric and
|
20 |
+
Blache, Philippe and
|
21 |
+
Choukri, Khalid and
|
22 |
+
Cieri, Christopher and
|
23 |
+
Declerck, Thierry and
|
24 |
+
Goggi, Sara and
|
25 |
+
Isahara, Hitoshi and
|
26 |
+
Maegaard, Bente and
|
27 |
+
Mariani, Joseph and
|
28 |
+
Mazo, H{\'e}l{\`e}ne and
|
29 |
+
Moreno, Asuncion and
|
30 |
+
Odijk, Jan and
|
31 |
+
Piperidis, Stelios",
|
32 |
+
booktitle = "Proceedings of the Twelfth Language Resources and Evaluation Conference",
|
33 |
+
month = may,
|
34 |
+
year = "2020",
|
35 |
+
address = "Marseille, France",
|
36 |
+
publisher = "European Language Resources Association",
|
37 |
+
url = "https://aclanthology.org/2020.lrec-1.316",
|
38 |
+
pages = "2596--2604",
|
39 |
+
language = "English",
|
40 |
+
ISBN = "979-10-95546-34-4",
|
41 |
+
}
|
42 |
+
"""
|
43 |
+
|
44 |
+
_LOCAL = False
|
45 |
+
_LANGUAGES = ["fil"]
|
46 |
+
_DATASETNAME = "fakenews_ph"
|
47 |
+
_DESCRIPTION = """\
|
48 |
+
Fake news articles were sourced from online sites that were tagged as fake
|
49 |
+
news sites by the non-profit independent media fact-checking organization
|
50 |
+
Verafiles and the National Union of Journalists in the Philippines (NUJP).
|
51 |
+
Real news articles were sourced from mainstream news websites in the
|
52 |
+
Philippines, including Pilipino Star Ngayon, Abante, and Bandera.
|
53 |
+
"""
|
54 |
+
|
55 |
+
_HOMEPAGE = "https://github.com/jcblaisecruz02/Tagalog-fake-news"
|
56 |
+
_LICENSE = Licenses.GPL_3_0.value
|
57 |
+
_URL = "https://s3.us-east-2.amazonaws.com/blaisecruz.com/datasets/fakenews/fakenews.zip"
|
58 |
+
|
59 |
+
_SUPPORTED_TASKS = [Tasks.HOAX_NEWS_CLASSIFICATION]
|
60 |
+
_SOURCE_VERSION = "1.0.0"
|
61 |
+
_SEACROWD_VERSION = "2024.06.20"
|
62 |
+
|
63 |
+
|
64 |
+
class FakeNewsFilipinoDataset(datasets.GeneratorBasedBuilder):
|
65 |
+
"""Fake News Filipino Dataset from https://huggingface.co/datasets/fake_news_filipino"""
|
66 |
+
|
67 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
68 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
69 |
+
|
70 |
+
SEACROWD_SCHEMA_NAME = "text"
|
71 |
+
LABEL_CLASSES = ["0", "1"]
|
72 |
+
|
73 |
+
BUILDER_CONFIGS = [
|
74 |
+
SEACrowdConfig(
|
75 |
+
name=f"{_DATASETNAME}_source",
|
76 |
+
version=SOURCE_VERSION,
|
77 |
+
description=f"{_DATASETNAME} source schema",
|
78 |
+
schema="source",
|
79 |
+
subset_id=_DATASETNAME,
|
80 |
+
),
|
81 |
+
SEACrowdConfig(
|
82 |
+
name=f"{_DATASETNAME}_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
83 |
+
version=SEACROWD_VERSION,
|
84 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
85 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
86 |
+
subset_id=_DATASETNAME,
|
87 |
+
),
|
88 |
+
]
|
89 |
+
|
90 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
91 |
+
|
92 |
+
def _info(self) -> datasets.DatasetInfo:
|
93 |
+
if self.config.schema == "source":
|
94 |
+
features = datasets.Features(
|
95 |
+
{
|
96 |
+
"article": datasets.Value("string"),
|
97 |
+
"label": datasets.features.ClassLabel(names=self.LABEL_CLASSES),
|
98 |
+
}
|
99 |
+
)
|
100 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
101 |
+
features = schemas.text_features(self.LABEL_CLASSES)
|
102 |
+
|
103 |
+
return datasets.DatasetInfo(
|
104 |
+
description=_DESCRIPTION,
|
105 |
+
features=features,
|
106 |
+
homepage=_HOMEPAGE,
|
107 |
+
license=_LICENSE,
|
108 |
+
citation=_CITATION,
|
109 |
+
)
|
110 |
+
|
111 |
+
def _split_generators(self, dl_manager: DownloadManager) -> List[datasets.SplitGenerator]:
|
112 |
+
"""Return SplitGenerators."""
|
113 |
+
data_dir = Path(dl_manager.download_and_extract(_URL))
|
114 |
+
train_path = data_dir / "fakenews" / "full.csv"
|
115 |
+
return [
|
116 |
+
datasets.SplitGenerator(
|
117 |
+
name=datasets.Split.TRAIN,
|
118 |
+
gen_kwargs={"filepath": train_path, "split": "train"},
|
119 |
+
)
|
120 |
+
]
|
121 |
+
|
122 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
123 |
+
"""Yield examples as (key, example) tuples"""
|
124 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
125 |
+
csv_reader = csv.reader(
|
126 |
+
csv_file,
|
127 |
+
quotechar='"',
|
128 |
+
delimiter=",",
|
129 |
+
quoting=csv.QUOTE_ALL,
|
130 |
+
skipinitialspace=True,
|
131 |
+
)
|
132 |
+
next(csv_reader)
|
133 |
+
for id_, row in enumerate(csv_reader):
|
134 |
+
label, article = row
|
135 |
+
if self.config.schema == "source":
|
136 |
+
yield id_, {"label": label, "article": article}
|
137 |
+
if self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
138 |
+
yield id_, {"id": id_, "label": label, "text": article}
|