File size: 5,172 Bytes
3dc5ee1 40b765b 3dc5ee1 9f40fc2 3dc5ee1 93f02a8 3dc5ee1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
import datasets
from datasets import Dataset, load_dataset
# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
TBA
"""
_DESCRIPTION = """\
Dataset from the Economy Watchers Survey for use as evaluation tasks
"""
_HOMEPAGE = "https://github.com/retarfi/economy-watchers-survey"
_LICENSE = "CC-BY 4.0"
VERSION = datasets.Version("0.1.0")
EWS_REPO_NAME = "retarfi/economy-watchers-survey"
LABEL_REASON_OTHER: str = "それ以外"
class EconomyWatchersSurveyConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
self.ews_version = kwargs.pop("ews_version", None)
super(EconomyWatchersSurveyConfig, self).__init__(**kwargs)
class EconomyWatchersSurveyDataset(datasets.GeneratorBasedBuilder):
BUILDER_CONFIG_CLASS = EconomyWatchersSurveyConfig
BUILDER_CONFIGS = [
EconomyWatchersSurveyConfig(
name="sentiment", version=VERSION, description="Sentiment analysis"
),
EconomyWatchersSurveyConfig(
name="domain", version=VERSION, description="Domain classification"
),
EconomyWatchersSurveyConfig(
name="reason",
version=VERSION,
description="Classification of reason to decision of sentiment",
),
]
def _info(self):
feat_label: datasets.ClassLabel
if self.config.name == "sentiment":
feat_label = datasets.ClassLabel(
num_classes=5, names=["×", "▲", "□", "○", "◎"]
)
elif self.config.name == "domain":
feat_label = datasets.ClassLabel(
num_classes=3, names=["家計動向", "企業動向", "雇用"]
)
elif self.config.name == "reason":
feat_label = datasets.ClassLabel(
num_classes=12,
names=[
"来客数の動き",
"販売量の動き",
"お客様の様子",
"受注量や販売量の動き",
"単価の動き",
"取引先の様子",
"求人数の動き",
"競争相手の様子",
"受注価格や販売価格の動き",
"周辺企業の様子",
"求職者数の動き",
LABEL_REASON_OTHER,
],
)
else:
raise NotImplementedError(self.config.name)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"text": datasets.Value("string"),
"label": feat_label,
"id": datasets.Value("string"),
}
),
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(
self, dl_manager: datasets.DownloadManager
) -> list[datasets.SplitGenerator]:
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN, gen_kwargs={"split": "train"}
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION, gen_kwargs={"split": "validation"}
),
datasets.SplitGenerator(
name=datasets.Split.TEST, gen_kwargs={"split": "test"}
),
]
def _generate_examples(self, split: str):
ds_current: Dataset = load_dataset(
EWS_REPO_NAME, "current", revision=self.config.ews_version, split=split
)
if self.config.name == "reason":
ds_current = ds_current.filter(lambda example: example["判断の理由"] is not None)
else:
ds_future: Dataset = load_dataset(
EWS_REPO_NAME, "future", revision=self.config.ews_version, split=split
)
ds_current = datasets.concatenate_datasets(
[
ds_current.remove_columns("判断の理由"),
ds_future.rename_columns(
{
"景気の先行き判断": "景気の現状判断",
"景気の先行きに対する判断理由": "追加説明及び具体的状況の説明",
}
),
]
)
for example in ds_current:
str_label: str
if self.config.name == "sentiment":
str_label = example["景気の現状判断"]
elif self.config.name == "domain":
str_label = example["関連"]
elif self.config.name == "reason":
str_label = example["判断の理由"]
if str_label not in self.info.features["label"].names:
str_label = LABEL_REASON_OTHER
yield example["id"], {
"id": example["id"],
"text": example["追加説明及び具体的状況の説明"],
"label": self.info.features["label"].str2int(str_label),
}
|