holylovenia
commited on
Commit
•
d951bbb
1
Parent(s):
546ab14
Upload lazada_review_filipino.py with huggingface_hub
Browse files- lazada_review_filipino.py +147 -0
lazada_review_filipino.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
16 |
+
"""
|
17 |
+
Filipino-Tagalog Product Reviews Sentiment Analysis
|
18 |
+
This is a machine learning dataset that can be used to analyze the sentiment of product reviews in Filipino-Tagalog.
|
19 |
+
The data is scraped from lazada Philippines.
|
20 |
+
"""
|
21 |
+
import os
|
22 |
+
from pathlib import Path
|
23 |
+
from typing import Dict, List, Tuple
|
24 |
+
import json
|
25 |
+
|
26 |
+
import datasets
|
27 |
+
|
28 |
+
from seacrowd.utils import schemas
|
29 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
30 |
+
from seacrowd.utils.constants import Tasks, Licenses
|
31 |
+
|
32 |
+
|
33 |
+
_CITATION = """@misc{github,
|
34 |
+
author={Eric Echemane},
|
35 |
+
title={Filipino-Tagalog-Product-Reviews-Sentiment-Analysis},
|
36 |
+
year={2022},
|
37 |
+
url={https://github.com/EricEchemane/Filipino-Tagalog-Product-Reviews-Sentiment-Analysis/tree/main},
|
38 |
+
}
|
39 |
+
"""
|
40 |
+
|
41 |
+
_DATASETNAME = "lazada_review_filipino"
|
42 |
+
|
43 |
+
|
44 |
+
_DESCRIPTION = """Filipino-Tagalog Product Reviews Sentiment Analysis
|
45 |
+
This is a machine learning dataset that can be used to analyze the sentiment of product reviews in Filipino-Tagalog.
|
46 |
+
The dataset contains over 900+ weakly annotated Filipino reviews scraped from the Lazada Philippines platform.
|
47 |
+
Each review is associated with a five star point rating where one is the lowest and five is the highest.
|
48 |
+
"""
|
49 |
+
|
50 |
+
|
51 |
+
_HOMEPAGE = "https://github.com/EricEchemane/Filipino-Tagalog-Product-Reviews-Sentiment-Analysis"
|
52 |
+
|
53 |
+
_LANGUAGES = ['fil', 'tgl']
|
54 |
+
|
55 |
+
_LICENSE = Licenses.UNKNOWN.value
|
56 |
+
|
57 |
+
|
58 |
+
_LOCAL = False
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
_URLS = {
|
63 |
+
_DATASETNAME: "https://raw.githubusercontent.com/EricEchemane/Filipino-Tagalog-Product-Reviews-Sentiment-Analysis/main/data/reviews.json",
|
64 |
+
}
|
65 |
+
|
66 |
+
|
67 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
|
68 |
+
|
69 |
+
|
70 |
+
_SOURCE_VERSION = "1.0.0"
|
71 |
+
|
72 |
+
_SEACROWD_VERSION = "2024.06.20"
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
class LazadaReviewFilipinoDataset(datasets.GeneratorBasedBuilder):
|
77 |
+
"""The dataset contains over 900+ weakly annotated Filipino reviews scraped from the Lazada Philippines platform"""
|
78 |
+
|
79 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
80 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
81 |
+
|
82 |
+
|
83 |
+
BUILDER_CONFIGS = [
|
84 |
+
SEACrowdConfig(
|
85 |
+
name="lazada_review_filipino_source",
|
86 |
+
version=SOURCE_VERSION,
|
87 |
+
description="lazada reviews in filipino source schema",
|
88 |
+
schema="source",
|
89 |
+
subset_id="lazada_review_filipino",
|
90 |
+
),
|
91 |
+
SEACrowdConfig(
|
92 |
+
name="lazada_review_filipino_seacrowd_text",
|
93 |
+
version=SEACROWD_VERSION,
|
94 |
+
description="lazada reviews in filipino SEACrowd schema",
|
95 |
+
schema="seacrowd_text",
|
96 |
+
subset_id="lazada_review_filipino",
|
97 |
+
),
|
98 |
+
]
|
99 |
+
|
100 |
+
DEFAULT_CONFIG_NAME = "lazada_review_filipino_source"
|
101 |
+
|
102 |
+
def _info(self) -> datasets.DatasetInfo:
|
103 |
+
|
104 |
+
if self.config.schema == "source":
|
105 |
+
features = datasets.Features({"index": datasets.Value("string"), "review": datasets.Value("string"),
|
106 |
+
"rating": datasets.Value("string")})
|
107 |
+
|
108 |
+
elif self.config.schema == "seacrowd_text":
|
109 |
+
features = schemas.text_features(label_names=["1", "2", "3", "4", "5"])
|
110 |
+
|
111 |
+
return datasets.DatasetInfo(
|
112 |
+
description=_DESCRIPTION,
|
113 |
+
features=features,
|
114 |
+
homepage=_HOMEPAGE,
|
115 |
+
license=_LICENSE,
|
116 |
+
citation=_CITATION,
|
117 |
+
)
|
118 |
+
|
119 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
120 |
+
"""Returns SplitGenerators."""
|
121 |
+
|
122 |
+
urls = _URLS[_DATASETNAME]
|
123 |
+
data_dir = dl_manager.download_and_extract(urls)
|
124 |
+
|
125 |
+
return [
|
126 |
+
datasets.SplitGenerator(
|
127 |
+
name=datasets.Split.TRAIN,
|
128 |
+
|
129 |
+
gen_kwargs={
|
130 |
+
"filepath": data_dir,
|
131 |
+
"split": "train",
|
132 |
+
},
|
133 |
+
)
|
134 |
+
]
|
135 |
+
|
136 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
137 |
+
"""Yields examples as (key, example) tuples."""
|
138 |
+
with open(filepath, 'r') as file:
|
139 |
+
data = json.load(file)
|
140 |
+
|
141 |
+
if self.config.schema == "source":
|
142 |
+
for i in range(len(data)):
|
143 |
+
yield i, {"index": str(i), "review": data[i]['review'], "rating": data[i]['rating']}
|
144 |
+
|
145 |
+
elif self.config.schema == "seacrowd_text":
|
146 |
+
for i in range(len(data)):
|
147 |
+
yield i, {"id": str(i), "text": data[i]['review'], "label": str(data[i]['rating'])}
|