Datasets:

Languages:
Japanese
ArXiv:
DOI:
License:
retarfi commited on
Commit
66d83ec
·
verified ·
1 Parent(s): 2355448

feat: mini batch to avoid segmentation fault

Browse files
Files changed (1) hide show
  1. economy-watchers-survey-evaluation.py +69 -30
economy-watchers-survey-evaluation.py CHANGED
@@ -1,5 +1,5 @@
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
@@ -102,38 +102,77 @@ class EconomyWatchersSurveyDataset(datasets.GeneratorBasedBuilder):
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_current = ds_current.filter(lambda example: example["判断の理由"] is not None)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  else:
111
- ds_future: Dataset = load_dataset(
112
  EWS_REPO_NAME, "future", revision=self.config.ews_version, split=split
113
  )
114
- ds_current = datasets.concatenate_datasets(
115
- [
116
- ds_current.remove_columns("判断の理由"),
117
- ds_future.rename_columns(
118
- {
119
- "景気の先行き判断": "景気の現状判断",
120
- "景気の先行きに対する判断理由": "追加説明及び具体的状況の説明",
121
- }
122
- ),
123
- ]
124
- )
125
- for example in ds_current:
126
- str_label: str
127
- if self.config.name == "sentiment":
128
- str_label = example["景気の現状判断"]
129
- elif self.config.name == "domain":
130
- str_label = example["関連"]
131
- elif self.config.name == "reason":
132
- str_label = example["判断の理由"]
133
- if str_label not in self.info.features["label"].names:
134
- str_label = LABEL_REASON_OTHER
135
- yield example["id"], {
136
- "id": example["id"],
137
- "text": example["追加説明及び具体的状況の説明"],
138
- "label": self.info.features["label"].str2int(str_label),
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
+ }