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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
from pathlib import Path
|
| 17 |
+
from typing import Dict, List, Tuple
|
| 18 |
+
|
| 19 |
+
import datasets
|
| 20 |
+
from pandas import read_excel
|
| 21 |
+
|
| 22 |
+
from seacrowd.utils import schemas
|
| 23 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 24 |
+
from seacrowd.utils.constants import TASK_TO_SCHEMA, Licenses, Tasks
|
| 25 |
+
|
| 26 |
+
_CITATION = """\
|
| 27 |
+
@inproceedings{koto-koto-2020-towards,
|
| 28 |
+
title = "Towards Computational Linguistics in {M}inangkabau Language:
|
| 29 |
+
Studies on Sentiment Analysis and Machine Translation",
|
| 30 |
+
author = "Koto, Fajri and
|
| 31 |
+
Koto, Ikhwan",
|
| 32 |
+
editor = "Nguyen, Minh Le and
|
| 33 |
+
Luong, Mai Chi and
|
| 34 |
+
Song, Sanghoun",
|
| 35 |
+
booktitle = "Proceedings of the 34th Pacific Asia Conference on Language,
|
| 36 |
+
Information and Computation",
|
| 37 |
+
month = oct,
|
| 38 |
+
year = "2020",
|
| 39 |
+
address = "Hanoi, Vietnam",
|
| 40 |
+
publisher = "Association for Computational Linguistics",
|
| 41 |
+
url = "https://aclanthology.org/2020.paclic-1.17",
|
| 42 |
+
pages = "138--148",
|
| 43 |
+
}
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
_DATASETNAME = "minang_senti"
|
| 47 |
+
|
| 48 |
+
_DESCRIPTION = """\
|
| 49 |
+
We release the Minangkabau corpus for sentiment analysis by manually translating
|
| 50 |
+
5,000 sentences of Indonesian sentiment analysis corpora. In this work, we
|
| 51 |
+
conduct a binary sentiment classification on positive and negative sentences by
|
| 52 |
+
first manually translating the Indonesian sentiment analysis corpus to the
|
| 53 |
+
Minangkabau language (Agam-Tanah Datar dialect)
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
_HOMEPAGE = "https://github.com/fajri91/minangNLP"
|
| 57 |
+
|
| 58 |
+
_LANGUAGES = ["ind", "min"]
|
| 59 |
+
|
| 60 |
+
_LICENSE = Licenses.MIT.value
|
| 61 |
+
|
| 62 |
+
_LOCAL = False
|
| 63 |
+
|
| 64 |
+
_BASE_URL = "https://github.com/fajri91/minangNLP/raw/master/sentiment/data/folds/{split}{index}.xlsx"
|
| 65 |
+
|
| 66 |
+
_SUPPORTED_TASKS = [Tasks.SENTIMENT_ANALYSIS]
|
| 67 |
+
_SEACROWD_SCHEMA = f"seacrowd_{TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]].lower()}" # text
|
| 68 |
+
|
| 69 |
+
_SOURCE_VERSION = "1.0.0"
|
| 70 |
+
|
| 71 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class MinangSentiDataset(datasets.GeneratorBasedBuilder):
|
| 75 |
+
"""Binary sentiment classification on manually translated Minangkabau corpus."""
|
| 76 |
+
|
| 77 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 78 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
| 79 |
+
|
| 80 |
+
BUILDER_CONFIGS = []
|
| 81 |
+
for subset in _LANGUAGES:
|
| 82 |
+
BUILDER_CONFIGS += [
|
| 83 |
+
SEACrowdConfig(
|
| 84 |
+
name=f"{_DATASETNAME}_{subset}_source",
|
| 85 |
+
version=SOURCE_VERSION,
|
| 86 |
+
description=f"{_DATASETNAME} {subset} source schema",
|
| 87 |
+
schema="source",
|
| 88 |
+
subset_id=subset,
|
| 89 |
+
),
|
| 90 |
+
SEACrowdConfig(
|
| 91 |
+
name=f"{_DATASETNAME}_{subset}_{_SEACROWD_SCHEMA}",
|
| 92 |
+
version=SEACROWD_VERSION,
|
| 93 |
+
description=f"{_DATASETNAME} {subset} SEACrowd schema",
|
| 94 |
+
schema=_SEACROWD_SCHEMA,
|
| 95 |
+
subset_id=subset,
|
| 96 |
+
),
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_{_LANGUAGES[0]}_source"
|
| 100 |
+
|
| 101 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 102 |
+
if self.config.schema == "source":
|
| 103 |
+
features = datasets.Features(
|
| 104 |
+
{
|
| 105 |
+
"minang": datasets.Value("string"),
|
| 106 |
+
"indo": datasets.Value("string"),
|
| 107 |
+
"sentiment": datasets.ClassLabel(names=["positive", "negative"]),
|
| 108 |
+
}
|
| 109 |
+
)
|
| 110 |
+
elif self.config.schema == _SEACROWD_SCHEMA:
|
| 111 |
+
features = schemas.text_features(label_names=["positive", "negative"])
|
| 112 |
+
|
| 113 |
+
return datasets.DatasetInfo(
|
| 114 |
+
description=_DESCRIPTION,
|
| 115 |
+
features=features,
|
| 116 |
+
homepage=_HOMEPAGE,
|
| 117 |
+
license=_LICENSE,
|
| 118 |
+
citation=_CITATION,
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 122 |
+
"""Returns SplitGenerators."""
|
| 123 |
+
train_urls = [_BASE_URL.format(split="train", index=i) for i in range(5)]
|
| 124 |
+
test_urls = [_BASE_URL.format(split="test", index=i) for i in range(5)]
|
| 125 |
+
dev_urls = [_BASE_URL.format(split="dev", index=i) for i in range(5)]
|
| 126 |
+
|
| 127 |
+
train_paths = [Path(dl_manager.download(url)) for url in train_urls]
|
| 128 |
+
test_paths = [Path(dl_manager.download(url)) for url in test_urls]
|
| 129 |
+
dev_paths = [Path(dl_manager.download(url)) for url in dev_urls]
|
| 130 |
+
|
| 131 |
+
return [
|
| 132 |
+
datasets.SplitGenerator(
|
| 133 |
+
name=datasets.Split.TRAIN,
|
| 134 |
+
gen_kwargs={
|
| 135 |
+
"filepath": train_paths,
|
| 136 |
+
},
|
| 137 |
+
),
|
| 138 |
+
datasets.SplitGenerator(
|
| 139 |
+
name=datasets.Split.TEST,
|
| 140 |
+
gen_kwargs={
|
| 141 |
+
"filepath": test_paths,
|
| 142 |
+
},
|
| 143 |
+
),
|
| 144 |
+
datasets.SplitGenerator(
|
| 145 |
+
name=datasets.Split.VALIDATION,
|
| 146 |
+
gen_kwargs={
|
| 147 |
+
"filepath": dev_paths,
|
| 148 |
+
},
|
| 149 |
+
),
|
| 150 |
+
]
|
| 151 |
+
|
| 152 |
+
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
| 153 |
+
"""Yields examples as (key, example) tuples."""
|
| 154 |
+
key = 0
|
| 155 |
+
for file in filepath:
|
| 156 |
+
data = read_excel(file)
|
| 157 |
+
for _, row in data.iterrows():
|
| 158 |
+
if self.config.schema == "source":
|
| 159 |
+
yield key, {
|
| 160 |
+
"minang": row["minang"],
|
| 161 |
+
"indo": row["indo"],
|
| 162 |
+
"sentiment": row["sentiment"],
|
| 163 |
+
}
|
| 164 |
+
elif self.config.schema == _SEACROWD_SCHEMA:
|
| 165 |
+
yield key, {
|
| 166 |
+
"id": str(key),
|
| 167 |
+
"text": row["minang"] if self.config.subset_id == "min" else row["indo"],
|
| 168 |
+
"label": row["sentiment"],
|
| 169 |
+
}
|
| 170 |
+
key += 1
|