feat: mini batch to avoid segmentation fault
Browse files
economy-watchers-survey-evaluation.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import datasets
|
2 |
-
from datasets import
|
3 |
|
4 |
# TODO: Add BibTeX citation
|
5 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
@@ -102,38 +102,77 @@ class EconomyWatchersSurveyDataset(datasets.GeneratorBasedBuilder):
|
|
102 |
]
|
103 |
|
104 |
def _generate_examples(self, split: str):
|
105 |
-
|
|
|
|
|
106 |
EWS_REPO_NAME, "current", revision=self.config.ews_version, split=split
|
107 |
)
|
|
|
|
|
108 |
if self.config.name == "reason":
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
else:
|
111 |
-
|
112 |
EWS_REPO_NAME, "future", revision=self.config.ews_version, split=split
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import datasets
|
2 |
+
from datasets import load_dataset
|
3 |
|
4 |
# TODO: Add BibTeX citation
|
5 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
|
|
102 |
]
|
103 |
|
104 |
def _generate_examples(self, split: str):
|
105 |
+
batch_size = 10000
|
106 |
+
|
107 |
+
ds_info_current = load_dataset(
|
108 |
EWS_REPO_NAME, "current", revision=self.config.ews_version, split=split
|
109 |
)
|
110 |
+
total_current = len(ds_info_current)
|
111 |
+
|
112 |
if self.config.name == "reason":
|
113 |
+
for start_idx in range(0, total_current, batch_size):
|
114 |
+
end_idx = min(start_idx + batch_size, total_current)
|
115 |
+
ds_current_batch = load_dataset(
|
116 |
+
EWS_REPO_NAME, "current", revision=self.config.ews_version,
|
117 |
+
split=f"{split}[{start_idx}:{end_idx}]"
|
118 |
+
)
|
119 |
+
|
120 |
+
ds_current_batch = ds_current_batch.filter(lambda example: example["判断の理由"] is not None)
|
121 |
+
for example in ds_current_batch:
|
122 |
+
str_label = example["判断の理由"]
|
123 |
+
if str_label not in self.info.features["label"].names:
|
124 |
+
str_label = LABEL_REASON_OTHER
|
125 |
+
|
126 |
+
yield example["id"], {
|
127 |
+
"id": example["id"],
|
128 |
+
"text": example["追加説明及び具体的状況の説明"],
|
129 |
+
"label": self.info.features["label"].str2int(str_label),
|
130 |
+
}
|
131 |
else:
|
132 |
+
ds_info_future = load_dataset(
|
133 |
EWS_REPO_NAME, "future", revision=self.config.ews_version, split=split
|
134 |
)
|
135 |
+
total_future = len(ds_info_future)
|
136 |
+
for start_idx in range(0, total_current, batch_size):
|
137 |
+
end_idx = min(start_idx + batch_size, total_current)
|
138 |
+
ds_current_batch = load_dataset(
|
139 |
+
EWS_REPO_NAME, "current", revision=self.config.ews_version,
|
140 |
+
split=f"{split}[{start_idx}:{end_idx}]"
|
141 |
+
)
|
142 |
+
|
143 |
+
ds_current_no_reason = ds_current_batch.remove_columns("判断の理由")
|
144 |
+
for example in ds_current_no_reason:
|
145 |
+
str_label: str
|
146 |
+
if self.config.name == "sentiment":
|
147 |
+
str_label = example["景気の現状判断"]
|
148 |
+
elif self.config.name == "domain":
|
149 |
+
str_label = example["関連"]
|
150 |
+
|
151 |
+
yield example["id"], {
|
152 |
+
"id": example["id"],
|
153 |
+
"text": example["追加説明及び具体的状況の説明"],
|
154 |
+
"label": self.info.features["label"].str2int(str_label),
|
155 |
+
}
|
156 |
+
|
157 |
+
for start_idx in range(0, total_future, batch_size):
|
158 |
+
end_idx = min(start_idx + batch_size, total_future)
|
159 |
+
|
160 |
+
ds_future_batch = load_dataset(
|
161 |
+
EWS_REPO_NAME, "future", revision=self.config.ews_version,
|
162 |
+
split=f"{split}[{start_idx}:{end_idx}]"
|
163 |
+
)
|
164 |
+
ds_future_renamed = ds_future_batch.rename_columns(
|
165 |
+
{"景気の先行き判断": "景気の現状判断", "景気の先行きに対する判断理由": "追加説明及び具体的状況の説明"}
|
166 |
+
)
|
167 |
+
for example in ds_future_renamed:
|
168 |
+
str_label: str
|
169 |
+
if self.config.name == "sentiment":
|
170 |
+
str_label = example["景気の現状判断"]
|
171 |
+
elif self.config.name == "domain":
|
172 |
+
str_label = example["関連"]
|
173 |
+
|
174 |
+
yield example["id"], {
|
175 |
+
"id": example["id"],
|
176 |
+
"text": example["追加説明及び具体的状況の説明"],
|
177 |
+
"label": self.info.features["label"].str2int(str_label),
|
178 |
+
}
|