Datasets:

Languages:
Thai
ArXiv:
License:
holylovenia commited on
Commit
90d1157
·
verified ·
1 Parent(s): 31804b4

Upload limesoda.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. limesoda.py +172 -0
limesoda.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Dict, List, Tuple
4
+
5
+ import datasets
6
+
7
+ from seacrowd.utils import schemas
8
+ from seacrowd.utils.configs import SEACrowdConfig
9
+ from seacrowd.utils.constants import Licenses, Tasks
10
+
11
+ _CITATION = """\
12
+ @INPROCEEDINGS{9678187,
13
+ author={Payoungkhamdee, Patomporn and Porkaew, Peerachet and Sinthunyathum, Atthasith and Songphum, Phattharaphon and Kawidam, Witsarut and Loha-Udom, Wichayut and Boonkwan, Prachya and Sutantayawalee, Vipas},
14
+ booktitle={2021 16th International Joint Symposium on Artificial Intelligence and Natural Language Processing (iSAI-NLP)},
15
+ title={LimeSoda: Dataset for Fake News Detection in Healthcare Domain},
16
+ year={2021},
17
+ volume={},
18
+ number={},
19
+ pages={1-6},
20
+ doi={10.1109/iSAI-NLP54397.2021.9678187}}
21
+ """
22
+
23
+ _DATASETNAME = "limesoda"
24
+
25
+ _DESCRIPTION = """\
26
+ Thai fake news dataset in the healthcare domain consisting of curate and manually annotated 7,191 documents
27
+ (only 4,141 documents contain token labels and are used as a test set of the baseline models).
28
+ Each document in the dataset is classified as fact, fake, or undefined.
29
+ """
30
+
31
+ _HOMEPAGE = "https://github.com/byinth/LimeSoda"
32
+
33
+ _LICENSE = Licenses.CC_BY_4_0.value
34
+
35
+ _LANGUAGES = ["tha"]
36
+ _LOCAL = False
37
+
38
+ _URLS = {
39
+ "split": {
40
+ "train": "https://raw.githubusercontent.com/byinth/LimeSoda/main/dataset_train_wo_tokentags_v1/train_v1.jsonl",
41
+ "val": "https://raw.githubusercontent.com/byinth/LimeSoda/main/dataset_train_wo_tokentags_v1/val_v1.jsonl",
42
+ "test": "https://raw.githubusercontent.com/byinth/LimeSoda/main/dataset_train_wo_tokentags_v1/test_v1.jsonl",
43
+ },
44
+ "raw": "https://raw.githubusercontent.com/byinth/LimeSoda/main/LimeSoda/Limesoda.jsonl",
45
+ }
46
+
47
+ _SUPPORTED_TASKS = [Tasks.HOAX_NEWS_CLASSIFICATION]
48
+
49
+ _SOURCE_VERSION = "1.0.0"
50
+
51
+ _SEACROWD_VERSION = "2024.06.20"
52
+
53
+
54
+ class LimeSodaDataset(datasets.GeneratorBasedBuilder):
55
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
56
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
57
+
58
+ BUILDER_CONFIGS = [
59
+ SEACrowdConfig(
60
+ name=f"{_DATASETNAME}_source",
61
+ version=SOURCE_VERSION,
62
+ description="limesoda source schema",
63
+ schema="source",
64
+ subset_id=_DATASETNAME,
65
+ ),
66
+ SEACrowdConfig(
67
+ name=f"{_DATASETNAME}_split_source",
68
+ version=SOURCE_VERSION,
69
+ description="limesoda source schema",
70
+ schema="source",
71
+ subset_id=f"{_DATASETNAME}_split",
72
+ ),
73
+ SEACrowdConfig(
74
+ name=f"{_DATASETNAME}_seacrowd_text",
75
+ version=SEACROWD_VERSION,
76
+ description="limesoda SEACrowd schema",
77
+ schema="seacrowd_text",
78
+ subset_id=_DATASETNAME,
79
+ ),
80
+ SEACrowdConfig(
81
+ name=f"{_DATASETNAME}_split_seacrowd_text",
82
+ version=SEACROWD_VERSION,
83
+ description="limesoda: split SEACrowd schema",
84
+ schema="seacrowd_text",
85
+ subset_id=f"{_DATASETNAME}_split",
86
+ ),
87
+ ]
88
+
89
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
90
+
91
+ def _info(self) -> datasets.DatasetInfo:
92
+ if self.config.schema == "source":
93
+ if self.config.subset_id == "limesoda":
94
+ features = datasets.Features(
95
+ {
96
+ "id": datasets.Value("string"),
97
+ "title": datasets.Value("string"),
98
+ "detail": datasets.Sequence(datasets.Value("string")),
99
+ "title_token_tags": datasets.Value("string"),
100
+ "detail_token_tags": datasets.Sequence(datasets.Value("string")),
101
+ "document_tag": datasets.Value("string"),
102
+ }
103
+ )
104
+ else:
105
+ features = datasets.Features({"id": datasets.Value("string"), "text": datasets.Value("string"), "document_tag": datasets.Value("string")})
106
+ elif self.config.schema == "seacrowd_text":
107
+ features = schemas.text_features(["Fact News", "Fake News", "Undefined"])
108
+
109
+ return datasets.DatasetInfo(
110
+ description=_DESCRIPTION,
111
+ features=features,
112
+ homepage=_HOMEPAGE,
113
+ license=_LICENSE,
114
+ citation=_CITATION,
115
+ )
116
+
117
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
118
+ """Returns SplitGenerators."""
119
+ path_dict = dl_manager.download_and_extract(_URLS)
120
+ if self.config.subset_id == "limesoda":
121
+ raw_path = path_dict["raw"]
122
+ return [
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.TRAIN,
125
+ gen_kwargs={
126
+ "filepath": raw_path,
127
+ },
128
+ ),
129
+ ]
130
+ elif self.config.subset_id == "limesoda_split":
131
+ train_path, val_path, test_path = path_dict["split"]["train"], path_dict["split"]["val"], path_dict["split"]["test"]
132
+ return [
133
+ datasets.SplitGenerator(
134
+ name=datasets.Split.TRAIN,
135
+ gen_kwargs={
136
+ "filepath": train_path,
137
+ },
138
+ ),
139
+ datasets.SplitGenerator(
140
+ name=datasets.Split.TEST,
141
+ gen_kwargs={
142
+ "filepath": test_path,
143
+ },
144
+ ),
145
+ datasets.SplitGenerator(
146
+ name=datasets.Split.VALIDATION,
147
+ gen_kwargs={
148
+ "filepath": val_path,
149
+ },
150
+ ),
151
+ ]
152
+
153
+ def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
154
+ with open(filepath, "r") as f:
155
+ entries = [json.loads(line) for line in f.readlines()]
156
+ if self.config.schema == "source":
157
+ if self.config.subset_id == "limesoda":
158
+ for i, row in enumerate(entries):
159
+ ex = {"id": str(i), "title": row["Title"], "detail": row["Detail"], "title_token_tags": row["Title Token Tags"], "detail_token_tags": row["Detail Token Tags"], "document_tag": row["Document Tag"]}
160
+ yield i, ex
161
+ else:
162
+ for i, row in enumerate(entries):
163
+ ex = {"id": str(i), "text": row["Text"], "document_tag": row["Document Tag"]}
164
+ yield i, ex
165
+ elif self.config.schema == "seacrowd_text":
166
+ for i, row in enumerate(entries):
167
+ ex = {
168
+ "id": str(i),
169
+ "text": row["Detail"] if self.config.subset_id == "limesoda" else row["Text"],
170
+ "label": row["Document Tag"],
171
+ }
172
+ yield i, ex