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
| 2 |
+
from typing import Dict, List, Tuple
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
from seacrowd.utils import schemas
|
| 8 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 9 |
+
from seacrowd.utils.constants import Tasks
|
| 10 |
+
|
| 11 |
+
_CITATION = """\
|
| 12 |
+
@misc{
|
| 13 |
+
research,
|
| 14 |
+
title={Jakartaresearch/google-play-review · datasets at hugging face},
|
| 15 |
+
url={https://huggingface.co/datasets/jakartaresearch/google-play-review},
|
| 16 |
+
author={Research, Jakarta AI}
|
| 17 |
+
}
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
_LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
| 21 |
+
_LOCAL = False
|
| 22 |
+
|
| 23 |
+
_DATASETNAME = "id_google_play_review"
|
| 24 |
+
_DESCRIPTION = """\
|
| 25 |
+
Indonesian Google Play Review, dataset scrapped from e-commerce app on Google Play for sentiment analysis.
|
| 26 |
+
Total number of data: 10041 (train: 7028, validation: 3012). Provided by Jakarta AI Research.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
_HOMEPAGE = "https://github.com/jakartaresearch/hf-datasets/tree/main/google-play-review/google-play-review"
|
| 30 |
+
_LICENSE = "CC-BY 4.0"
|
| 31 |
+
|
| 32 |
+
_URLS = {
|
| 33 |
+
_DATASETNAME: {
|
| 34 |
+
"train": "https://media.githubusercontent.com/media/jakartaresearch/hf-datasets/main/google-play-review/google-play-review/train.csv",
|
| 35 |
+
"valid": "https://media.githubusercontent.com/media/jakartaresearch/hf-datasets/main/google-play-review/google-play-review/validation.csv",
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
|
| 40 |
+
|
| 41 |
+
_SOURCE_VERSION = "1.0.0"
|
| 42 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class IDGooglePlayReview(datasets.GeneratorBasedBuilder):
|
| 46 |
+
"""
|
| 47 |
+
Indonesian Google Play Review is a dataset containing reviews from Google Play Indonesia, used for sentiment
|
| 48 |
+
analysis.
|
| 49 |
+
The language content is mainly Indonesian, however beware of context-switching (some sentences are partly or
|
| 50 |
+
entirely in English).
|
| 51 |
+
The available labels:
|
| 52 |
+
label: ['pos', 'neg'] for source and seacrowd_text scheme
|
| 53 |
+
stars: [1, 2, 3, 4, 5] for source
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 57 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
| 58 |
+
|
| 59 |
+
BUILDER_CONFIGS = [
|
| 60 |
+
SEACrowdConfig(
|
| 61 |
+
name="id_google_play_review_source",
|
| 62 |
+
version=SOURCE_VERSION,
|
| 63 |
+
description="id_google_play_review source schema",
|
| 64 |
+
schema="source",
|
| 65 |
+
subset_id="id_google_play_review",
|
| 66 |
+
),
|
| 67 |
+
SEACrowdConfig(
|
| 68 |
+
name="id_google_play_review_posneg_source",
|
| 69 |
+
version=SOURCE_VERSION,
|
| 70 |
+
description="id_google_play_review source schema",
|
| 71 |
+
schema="source",
|
| 72 |
+
subset_id="id_google_play_review_posneg",
|
| 73 |
+
),
|
| 74 |
+
SEACrowdConfig(
|
| 75 |
+
name="id_google_play_review_seacrowd_text",
|
| 76 |
+
version=SEACROWD_VERSION,
|
| 77 |
+
description="id_google_play_review Nusantara schema, 1-5 stars rating only (for pos/neg labels, please use the subset_id \"id_google_play_review_posneg\")",
|
| 78 |
+
schema="seacrowd_text",
|
| 79 |
+
subset_id="id_google_play_review",
|
| 80 |
+
),
|
| 81 |
+
SEACrowdConfig(
|
| 82 |
+
name="id_google_play_review_posneg_seacrowd_text",
|
| 83 |
+
version=SEACROWD_VERSION,
|
| 84 |
+
description="id_google_play_review Nusantara schema, pos/neg label only",
|
| 85 |
+
schema="seacrowd_text",
|
| 86 |
+
subset_id="id_google_play_review_posneg",
|
| 87 |
+
),
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
DEFAULT_CONFIG_NAME = "id_google_play_review_source"
|
| 91 |
+
|
| 92 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 93 |
+
|
| 94 |
+
# Create the source schema; this schema will keep all keys/information/labels as close to the original dataset
|
| 95 |
+
# as possible.
|
| 96 |
+
|
| 97 |
+
# You can arbitrarily nest lists and dictionaries.
|
| 98 |
+
# For iterables, use lists over tuples or `datasets.Sequence`
|
| 99 |
+
|
| 100 |
+
if self.config.schema == "source":
|
| 101 |
+
features = datasets.Features({
|
| 102 |
+
"text": datasets.Value("string"),
|
| 103 |
+
"label": datasets.Value("string"),
|
| 104 |
+
"stars": datasets.Value("int8")
|
| 105 |
+
})
|
| 106 |
+
elif self.config.schema == "seacrowd_text":
|
| 107 |
+
if self.config.subset_id == "id_google_play_review_posneg":
|
| 108 |
+
features = schemas.text_features(["pos", "neg"])
|
| 109 |
+
elif self.config.subset_id == "id_google_play_review":
|
| 110 |
+
features = schemas.text_features(["1", "2", "3", "4", "5"])
|
| 111 |
+
else:
|
| 112 |
+
raise ValueError(f"Invalid config: {self.config.name}")
|
| 113 |
+
|
| 114 |
+
return datasets.DatasetInfo(
|
| 115 |
+
description=_DESCRIPTION,
|
| 116 |
+
features=features,
|
| 117 |
+
homepage=_HOMEPAGE,
|
| 118 |
+
license=_LICENSE,
|
| 119 |
+
citation=_CITATION,
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 123 |
+
"""Returns SplitGenerators."""
|
| 124 |
+
urls = _URLS[_DATASETNAME]
|
| 125 |
+
train_data_path = Path(dl_manager.download(urls["train"]))
|
| 126 |
+
valid_data_path = Path(dl_manager.download(urls["valid"]))
|
| 127 |
+
|
| 128 |
+
return [
|
| 129 |
+
datasets.SplitGenerator(
|
| 130 |
+
name=datasets.Split.TRAIN,
|
| 131 |
+
gen_kwargs={"filepath": train_data_path, "split": "train"},
|
| 132 |
+
),
|
| 133 |
+
datasets.SplitGenerator(
|
| 134 |
+
name=datasets.Split.VALIDATION,
|
| 135 |
+
gen_kwargs={"filepath": valid_data_path, "split": "valid"},
|
| 136 |
+
),
|
| 137 |
+
]
|
| 138 |
+
|
| 139 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
| 140 |
+
"""Yields examples as (key, example) tuples."""
|
| 141 |
+
|
| 142 |
+
df = pd.read_csv(filepath, sep=",").reset_index()
|
| 143 |
+
for row in df.itertuples(index=False):
|
| 144 |
+
if self.config.schema == "source":
|
| 145 |
+
example = {"text": row.text, "label": row.label, "stars": row.stars}
|
| 146 |
+
yield row.index, example
|
| 147 |
+
elif self.config.schema == "seacrowd_text":
|
| 148 |
+
if self.config.subset_id == "id_google_play_review_posneg":
|
| 149 |
+
example = {"id": row.index, "text": row.text, "label": row.label}
|
| 150 |
+
elif self.config.subset_id == "id_google_play_review":
|
| 151 |
+
example = {"id": row.index, "text": row.text, "label": str(row.stars)}
|
| 152 |
+
else:
|
| 153 |
+
raise ValueError(f"Invalid config: {self.config.name}")
|
| 154 |
+
yield row.index, example
|