Upload vispamreviews.py with huggingface_hub
Browse files- vispamreviews.py +179 -0
vispamreviews.py
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 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 |
+
import os
|
16 |
+
from typing import Dict, List, Tuple
|
17 |
+
|
18 |
+
import datasets
|
19 |
+
import pandas
|
20 |
+
|
21 |
+
from seacrowd.utils import schemas
|
22 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
23 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
24 |
+
|
25 |
+
_CITATION = """
|
26 |
+
@InProceedings{10.1007/978-3-031-21743-2_48,
|
27 |
+
author="Van Dinh, Co
|
28 |
+
and Luu, Son T.
|
29 |
+
and Nguyen, Anh Gia-Tuan",
|
30 |
+
editor="Nguyen, Ngoc Thanh
|
31 |
+
and Tran, Tien Khoa
|
32 |
+
and Tukayev, Ualsher
|
33 |
+
and Hong, Tzung-Pei
|
34 |
+
and Trawi{\'{n}}ski, Bogdan
|
35 |
+
and Szczerbicki, Edward",
|
36 |
+
title="Detecting Spam Reviews on Vietnamese E-Commerce Websites",
|
37 |
+
booktitle="Intelligent Information and Database Systems",
|
38 |
+
year="2022",
|
39 |
+
publisher="Springer International Publishing",
|
40 |
+
address="Cham",
|
41 |
+
pages="595--607",
|
42 |
+
abstract="The reviews of customers play an essential role in online shopping.
|
43 |
+
People often refer to reviews or comments of previous customers to decide whether
|
44 |
+
to buy a new product. Catching up with this behavior, some people create untruths and
|
45 |
+
illegitimate reviews to hoax customers about the fake quality of products. These are called
|
46 |
+
spam reviews, confusing consumers on online shopping platforms and negatively affecting online
|
47 |
+
shopping behaviors. We propose the dataset called ViSpamReviews, which has a strict annotation
|
48 |
+
procedure for detecting spam reviews on e-commerce platforms. Our dataset consists of two tasks:
|
49 |
+
the binary classification task for detecting whether a review is spam or not and the multi-class
|
50 |
+
classification task for identifying the type of spam. The PhoBERT obtained the highest results on
|
51 |
+
both tasks, 86.89%, and 72.17%, respectively, by macro average F1 score.",
|
52 |
+
isbn="978-3-031-21743-2"
|
53 |
+
}
|
54 |
+
"""
|
55 |
+
|
56 |
+
_LOCAL = False
|
57 |
+
_LANGUAGES = ["vie"]
|
58 |
+
_DATASETNAME = "vispamreviews"
|
59 |
+
_DESCRIPTION = """
|
60 |
+
The dataset was collected from leading online shopping platforms in Vietnam. Some of the most recent
|
61 |
+
selling products for each product category were selected and up to 15 reviews per product were collected.
|
62 |
+
Each review was then labeled as either NO-SPAM, SPAM-1 (fake review), SPAM-2 (review on brand only), or
|
63 |
+
SPAM-3 (irrelevant content).
|
64 |
+
"""
|
65 |
+
|
66 |
+
_HOMEPAGE = "https://github.com/sonlam1102/vispamdetection/"
|
67 |
+
_LICENSE = Licenses.CC_BY_NC_4_0.value
|
68 |
+
_URL = "https://raw.githubusercontent.com/sonlam1102/vispamdetection/main/dataset/vispamdetection_dataset.zip"
|
69 |
+
|
70 |
+
_Split_Path = {
|
71 |
+
"train": "dataset/train.csv",
|
72 |
+
"validation": "dataset/dev.csv",
|
73 |
+
"test": "dataset/test.csv",
|
74 |
+
}
|
75 |
+
|
76 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS] # Text Classification
|
77 |
+
_SOURCE_VERSION = "1.0.0"
|
78 |
+
_SEACROWD_VERSION = "2024.06.20"
|
79 |
+
|
80 |
+
|
81 |
+
class ViSpamReviewsDataset(datasets.GeneratorBasedBuilder):
|
82 |
+
"""
|
83 |
+
The SeaCrowd dataloader for the review dataset shopping platforms in Vietnam (ViSpamReviews).
|
84 |
+
"""
|
85 |
+
|
86 |
+
CLASS_LABELS = [0, 1]
|
87 |
+
SPAM_TYPE_LABELS = [0, 1, 2, 3]
|
88 |
+
|
89 |
+
BUILDER_CONFIGS = [
|
90 |
+
SEACrowdConfig(
|
91 |
+
name=f"{_DATASETNAME}_source",
|
92 |
+
version=datasets.Version(_SOURCE_VERSION),
|
93 |
+
description=f"{_DATASETNAME} source schema",
|
94 |
+
schema="source",
|
95 |
+
subset_id=f"{_DATASETNAME}",
|
96 |
+
),
|
97 |
+
SEACrowdConfig(
|
98 |
+
name=f"{_DATASETNAME}_spam_source",
|
99 |
+
version=datasets.Version(_SOURCE_VERSION),
|
100 |
+
description=f"{_DATASETNAME} source schema",
|
101 |
+
schema="source",
|
102 |
+
subset_id=f"{_DATASETNAME}",
|
103 |
+
),
|
104 |
+
SEACrowdConfig(
|
105 |
+
name=f"{_DATASETNAME}_seacrowd_text",
|
106 |
+
version=datasets.Version(_SEACROWD_VERSION),
|
107 |
+
description=f"{_DATASETNAME} SEACrowd schema ",
|
108 |
+
schema="seacrowd_text",
|
109 |
+
subset_id=f"{_DATASETNAME}",
|
110 |
+
),
|
111 |
+
SEACrowdConfig(
|
112 |
+
name=f"{_DATASETNAME}_spam_seacrowd_text",
|
113 |
+
version=datasets.Version(_SEACROWD_VERSION),
|
114 |
+
description=f"{_DATASETNAME} SEACrowd schema ",
|
115 |
+
schema="seacrowd_text",
|
116 |
+
subset_id=f"{_DATASETNAME}_spam",
|
117 |
+
),
|
118 |
+
]
|
119 |
+
|
120 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
121 |
+
|
122 |
+
def _info(self) -> datasets.DatasetInfo:
|
123 |
+
if self.config.name.endswith("source"):
|
124 |
+
features = (datasets.Features
|
125 |
+
(
|
126 |
+
{"id": datasets.Value("int32"),
|
127 |
+
"text": datasets.Value("string"),
|
128 |
+
"label": datasets.Value("string"),
|
129 |
+
"spam_label": datasets.Value("string"),
|
130 |
+
"rating": datasets.Value("int32")
|
131 |
+
}
|
132 |
+
))
|
133 |
+
|
134 |
+
elif self.config.name == "vispamreviews_seacrowd_text":
|
135 |
+
features = schemas.text_features(label_names=self.CLASS_LABELS)
|
136 |
+
elif self.config.name == "vispamreviews_spam_seacrowd_text":
|
137 |
+
features = schemas.text_features(label_names=self.SPAM_TYPE_LABELS)
|
138 |
+
else:
|
139 |
+
raise ValueError(f"Invalid schema {self.config.name}")
|
140 |
+
|
141 |
+
return datasets.DatasetInfo(
|
142 |
+
description=_DESCRIPTION,
|
143 |
+
features=features,
|
144 |
+
homepage=_HOMEPAGE,
|
145 |
+
license=_LICENSE,
|
146 |
+
citation=_CITATION,
|
147 |
+
)
|
148 |
+
|
149 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
150 |
+
file_paths = dl_manager.download_and_extract(_URL)
|
151 |
+
return [
|
152 |
+
datasets.SplitGenerator(
|
153 |
+
name=datasets.Split.TRAIN,
|
154 |
+
gen_kwargs={"filepath": os.path.join(file_paths, _Split_Path["train"])},
|
155 |
+
),
|
156 |
+
datasets.SplitGenerator(
|
157 |
+
name=datasets.Split.VALIDATION,
|
158 |
+
gen_kwargs={"filepath": os.path.join(file_paths, _Split_Path["validation"])},
|
159 |
+
),
|
160 |
+
datasets.SplitGenerator(
|
161 |
+
name=datasets.Split.TEST,
|
162 |
+
gen_kwargs={"filepath": os.path.join(file_paths, _Split_Path["test"])},
|
163 |
+
),
|
164 |
+
]
|
165 |
+
|
166 |
+
def _generate_examples(self, filepath) -> Tuple[int, Dict]:
|
167 |
+
"""Yields examples as (key, example) tuples."""
|
168 |
+
data_lines = pandas.read_csv(filepath)
|
169 |
+
for rid, row in enumerate(data_lines.itertuples()):
|
170 |
+
if self.config.name.endswith("source"):
|
171 |
+
example = {"id": str(rid), "text": row.Comment, "label": row.Label, "spam_label": row.SpamLabel,
|
172 |
+
"rating": row.Rating}
|
173 |
+
elif self.config.name == "vispamreviews_seacrowd_text":
|
174 |
+
example = {"id": str(rid), "text": row.Comment, "label": row.Label}
|
175 |
+
elif self.config.name == "vispamreviews_spam_seacrowd_text":
|
176 |
+
example = {"id": str(rid), "text": row.Comment, "label": row.SpamLabel}
|
177 |
+
else:
|
178 |
+
raise ValueError(f"Invalid schema {self.config.schema}")
|
179 |
+
yield rid, example
|