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