File size: 7,535 Bytes
3dc5ee1 66d83ec 3dc5ee1 302319f 3dc5ee1 302319f 3dc5ee1 302319f 66d83ec 3dc5ee1 66d83ec 40b765b 66d83ec 302319f 66d83ec 302319f 66d83ec 40b765b 66d83ec 3dc5ee1 66d83ec |
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
import datasets
from datasets import 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.2")
EWS_REPO_NAME = "retarfi/economy-watchers-survey"
LABEL_REASON_OTHER: str = "それ以外"
DISABLED_BARS: bool = datasets.are_progress_bars_disabled()
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):
batch_size = 1000
ds_info_current = load_dataset(
EWS_REPO_NAME, "current", revision=self.config.ews_version, split=split
)
total_current = len(ds_info_current)
if self.config.name == "reason":
for start_idx in range(0, total_current, batch_size):
end_idx = min(start_idx + batch_size, total_current)
ds_current_batch = load_dataset(
EWS_REPO_NAME, "current", revision=self.config.ews_version,
split=f"{split}[{start_idx}:{end_idx}]"
)
if not DISABLED_BARS:
datasets.disable_progress_bars()
ds_current_batch = ds_current_batch.filter(lambda example: example["判断の理由"] is not None)
if not DISABLED_BARS:
datasets.enable_progress_bars()
for example in ds_current_batch:
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),
}
else:
ds_info_future = load_dataset(
EWS_REPO_NAME, "future", revision=self.config.ews_version, split=split
)
total_future = len(ds_info_future)
for start_idx in range(0, total_current, batch_size):
end_idx = min(start_idx + batch_size, total_current)
ds_current_batch = load_dataset(
EWS_REPO_NAME, "current", revision=self.config.ews_version,
split=f"{split}[{start_idx}:{end_idx}]"
)
ds_current_no_reason = ds_current_batch.remove_columns("判断の理由")
for example in ds_current_no_reason:
str_label: str
if self.config.name == "sentiment":
str_label = example["景気の現状判断"]
elif self.config.name == "domain":
str_label = example["関連"]
yield example["id"], {
"id": example["id"],
"text": example["追加説明及び具体的状況の説明"],
"label": self.info.features["label"].str2int(str_label),
}
for start_idx in range(0, total_future, batch_size):
end_idx = min(start_idx + batch_size, total_future)
ds_future_batch = load_dataset(
EWS_REPO_NAME, "future", revision=self.config.ews_version,
split=f"{split}[{start_idx}:{end_idx}]"
)
ds_future_renamed = ds_future_batch.rename_columns(
{"景気の先行き判断": "景気の現状判断", "景気の先行きに対する判断理由": "追加説明及び具体的状況の説明"}
)
for example in ds_future_renamed:
str_label: str
if self.config.name == "sentiment":
str_label = example["景気の現状判断"]
elif self.config.name == "domain":
str_label = example["関連"]
yield example["id"], {
"id": example["id"],
"text": example["追加説明及び具体的状況の説明"],
"label": self.info.features["label"].str2int(str_label),
}
|