Commit
•
95f1147
1
Parent(s):
9413640
Upload shopee_reviews_tagalog.py with huggingface_hub
Browse files- shopee_reviews_tagalog.py +123 -0
shopee_reviews_tagalog.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = """
|
13 |
+
@article{riegoenhancement,
|
14 |
+
title={Enhancement to Low-Resource Text Classification via Sequential Transfer Learning},
|
15 |
+
author={Riego, Neil Christian R. and Villarba, Danny Bell and Sison, Ariel Antwaun Rolando C. and Pineda, Fernandez C. and Lagunzad, Herminiño C.}
|
16 |
+
journal={United International Journal for Research & Technology},
|
17 |
+
volume={04},
|
18 |
+
issue={08},
|
19 |
+
pages={72--82}
|
20 |
+
}
|
21 |
+
"""
|
22 |
+
|
23 |
+
_LOCAL = False
|
24 |
+
_LANGUAGES = ["fil", "tgl"]
|
25 |
+
_DATASETNAME = "shopee_reviews_tagalog"
|
26 |
+
_DESCRIPTION = """\
|
27 |
+
The Shopee reviews dataset is constructed by randomly taking 2100 training
|
28 |
+
samples and 450 samples for testing and validation for each review star from 1
|
29 |
+
to 5. In total, there are 10500 training samples and 2250 each in validation and
|
30 |
+
testing samples.
|
31 |
+
"""
|
32 |
+
|
33 |
+
_HOMEPAGE = "https://huggingface.co/datasets/scaredmeow/shopee-reviews-tl-stars"
|
34 |
+
_LICENSE = Licenses.MPL_2_0.value
|
35 |
+
_URLS = {
|
36 |
+
"train": "https://huggingface.co/datasets/scaredmeow/shopee-reviews-tl-stars/resolve/main/train.csv",
|
37 |
+
"validation": "https://huggingface.co/datasets/scaredmeow/shopee-reviews-tl-stars/resolve/main/validation.csv",
|
38 |
+
"test": "https://huggingface.co/datasets/scaredmeow/shopee-reviews-tl-stars/resolve/main/test.csv",
|
39 |
+
}
|
40 |
+
|
41 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
|
42 |
+
_SOURCE_VERSION = "1.0.0"
|
43 |
+
_SEACROWD_VERSION = "2024.06.20"
|
44 |
+
|
45 |
+
|
46 |
+
class ShopeeReviewsTagalogDataset(datasets.GeneratorBasedBuilder):
|
47 |
+
"""Shopee Reviews Tagalog dataset from https://huggingface.co/datasets/scaredmeow/shopee-reviews-tl-stars"""
|
48 |
+
|
49 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
50 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
51 |
+
|
52 |
+
SEACROWD_SCHEMA_NAME = "text"
|
53 |
+
# "N" means N+1 star(s) review, e.g. "2" means 3 stars review
|
54 |
+
LABEL_CLASSES = ["0", "1", "2", "3", "4"]
|
55 |
+
|
56 |
+
BUILDER_CONFIGS = [
|
57 |
+
SEACrowdConfig(
|
58 |
+
name=f"{_DATASETNAME}_source",
|
59 |
+
version=SOURCE_VERSION,
|
60 |
+
description=f"{_DATASETNAME} source schema",
|
61 |
+
schema="source",
|
62 |
+
subset_id=_DATASETNAME,
|
63 |
+
),
|
64 |
+
SEACrowdConfig(
|
65 |
+
name=f"{_DATASETNAME}_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
66 |
+
version=SEACROWD_VERSION,
|
67 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
68 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
69 |
+
subset_id=_DATASETNAME,
|
70 |
+
),
|
71 |
+
]
|
72 |
+
|
73 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
74 |
+
|
75 |
+
def _info(self) -> datasets.DatasetInfo:
|
76 |
+
# The SEACrowd schema and the source schema is the same
|
77 |
+
features = schemas.text_features(self.LABEL_CLASSES)
|
78 |
+
return datasets.DatasetInfo(
|
79 |
+
description=_DESCRIPTION,
|
80 |
+
features=features,
|
81 |
+
homepage=_HOMEPAGE,
|
82 |
+
license=_LICENSE,
|
83 |
+
citation=_CITATION,
|
84 |
+
)
|
85 |
+
|
86 |
+
def _split_generators(self, dl_manager: DownloadManager) -> List[datasets.SplitGenerator]:
|
87 |
+
data_files = {
|
88 |
+
"train": Path(dl_manager.download_and_extract(_URLS["train"])),
|
89 |
+
"validation": Path(dl_manager.download_and_extract(_URLS["validation"])),
|
90 |
+
"test": Path(dl_manager.download_and_extract(_URLS["test"])),
|
91 |
+
}
|
92 |
+
|
93 |
+
return [
|
94 |
+
datasets.SplitGenerator(
|
95 |
+
name=datasets.Split.TRAIN,
|
96 |
+
gen_kwargs={"filepath": data_files["train"], "split": "train"},
|
97 |
+
),
|
98 |
+
datasets.SplitGenerator(
|
99 |
+
name=datasets.Split.VALIDATION,
|
100 |
+
gen_kwargs={"filepath": data_files["validation"], "split": "validation"},
|
101 |
+
),
|
102 |
+
datasets.SplitGenerator(
|
103 |
+
name=datasets.Split.TEST,
|
104 |
+
gen_kwargs={"filepath": data_files["test"], "split": "test"},
|
105 |
+
),
|
106 |
+
]
|
107 |
+
|
108 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
109 |
+
"""Yield (idx, example) tuples"""
|
110 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
111 |
+
csv_reader = csv.reader(
|
112 |
+
csv_file,
|
113 |
+
quotechar='"',
|
114 |
+
delimiter=",",
|
115 |
+
quoting=csv.QUOTE_ALL,
|
116 |
+
skipinitialspace=True,
|
117 |
+
)
|
118 |
+
|
119 |
+
next(csv_reader)
|
120 |
+
for idx, row in enumerate(csv_reader):
|
121 |
+
text, label = row
|
122 |
+
example = {"id": idx, "text": text, "label": label}
|
123 |
+
yield idx, example
|