system HF staff commited on
Commit
ca521b1
1 Parent(s): 5c158d6

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (1) hide show
  1. mdd.py +61 -65
mdd.py CHANGED
@@ -14,9 +14,6 @@
14
  # limitations under the License.
15
  """Movie Dialog Dataset."""
16
 
17
-
18
- import os
19
-
20
  import datasets
21
 
22
 
@@ -134,28 +131,22 @@ class Mdd(datasets.GeneratorBasedBuilder):
134
  my_urls = ZIP_URL # Cannot download just one single type as it is a compressed file.
135
  else:
136
  my_urls = REDDIT_URL
137
- data_dir = dl_manager.download_and_extract(my_urls)
138
  splits = [
139
  datasets.SplitGenerator(
140
  name=datasets.Split.TRAIN,
141
  # These kwargs will be passed to _generate_examples
142
- gen_kwargs={
143
- "filepath": os.path.join(data_dir, paths[self.config.name]["train"]),
144
- },
145
  ),
146
  datasets.SplitGenerator(
147
  name=datasets.Split.TEST,
148
  # These kwargs will be passed to _generate_examples
149
- gen_kwargs={
150
- "filepath": os.path.join(data_dir, paths[self.config.name]["test"]),
151
- },
152
  ),
153
  datasets.SplitGenerator(
154
  name=datasets.Split.VALIDATION,
155
  # These kwargs will be passed to _generate_examples
156
- gen_kwargs={
157
- "filepath": os.path.join(data_dir, paths[self.config.name]["dev"]),
158
- },
159
  ),
160
  ]
161
  if self.config.name == "task4_reddit":
@@ -164,71 +155,76 @@ class Mdd(datasets.GeneratorBasedBuilder):
164
  name=datasets.Split("cand_valid"),
165
  # These kwargs will be passed to _generate_examples
166
  gen_kwargs={
167
- "filepath": os.path.join(data_dir, paths[self.config.name]["cand_valid"]),
 
168
  },
169
  ),
170
  datasets.SplitGenerator(
171
  name=datasets.Split("cand_test"),
172
  # These kwargs will be passed to _generate_examples
173
  gen_kwargs={
174
- "filepath": os.path.join(data_dir, paths[self.config.name]["cand_test"]),
 
175
  },
176
  ),
177
  ]
178
  return splits
179
 
180
- def _generate_examples(self, filepath):
181
- if "cand" not in filepath:
182
- with open(filepath, encoding="utf-8") as f:
183
- dialogue_turns = []
184
- example_idx = 0
185
- for idx, line in enumerate(f):
186
- if line.strip() == "":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  if dialogue_turns != []:
188
  yield example_idx, {"dialogue_turns": dialogue_turns}
189
- example_idx += 1
190
- dialogue_turns = []
191
- elif line.strip().split()[0] == "1": # New convo
192
- if dialogue_turns != []: # Already some convo, flush it out
193
- yield example_idx, {"dialogue_turns": dialogue_turns}
194
- example_idx += 1
195
- dialogue_turns = []
196
- exchange = line[len(line.split()[0]) :].strip().split("\t") # Skip the number in the front
197
- sp1 = exchange[0]
198
- sp2 = exchange[-1] # Might contain multiple tabs in between.
199
- dialogue_turns.append({"speaker": 0, "utterance": sp1})
200
- dialogue_turns.append({"speaker": 1, "utterance": sp2})
201
- else:
202
- exchange = line[len(line.split()[0]) :].strip().split("\t") # Skip the number in the front
203
- sp1 = exchange[0]
204
- sp2 = exchange[-1] # Might contain multiple tabs in between.
205
- dialogue_turns.append({"speaker": 0, "utterance": sp1})
206
- dialogue_turns.append({"speaker": 1, "utterance": sp2})
207
  else:
208
- if dialogue_turns != []:
209
- yield example_idx, {"dialogue_turns": dialogue_turns}
210
- else:
211
- with open(filepath, encoding="utf-8") as f:
212
- dialogue_turns = []
213
- example_idx = 0
214
- for idx, line in enumerate(f):
215
- if line.strip() == "":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  if dialogue_turns != []:
217
  yield example_idx, {"dialogue_turns": dialogue_turns}
218
- example_idx += 1
219
- dialogue_turns = []
220
- elif line.strip().split()[0] == "1": # New convo
221
- if dialogue_turns != []: # Already some convo, flush it out
222
- yield example_idx, {"dialogue_turns": dialogue_turns}
223
- example_idx += 1
224
- dialogue_turns = []
225
- exchange = line[len(line.split()[0]) :].strip() # Skip the number in the front
226
- sp1 = exchange
227
- dialogue_turns.append({"speaker": 0, "utterance": sp1})
228
- else:
229
- exchange = line[len(line.split()[0]) :].strip() # Skip the number in the front
230
- sp1 = exchange
231
- dialogue_turns.append({"speaker": 0, "utterance": sp1})
232
- else: # Last line, new example
233
- if dialogue_turns != []:
234
- yield example_idx, {"dialogue_turns": dialogue_turns}
 
14
  # limitations under the License.
15
  """Movie Dialog Dataset."""
16
 
 
 
 
17
  import datasets
18
 
19
 
 
131
  my_urls = ZIP_URL # Cannot download just one single type as it is a compressed file.
132
  else:
133
  my_urls = REDDIT_URL
134
+ archive = dl_manager.download(my_urls)
135
  splits = [
136
  datasets.SplitGenerator(
137
  name=datasets.Split.TRAIN,
138
  # These kwargs will be passed to _generate_examples
139
+ gen_kwargs={"filepath": paths[self.config.name]["train"], "files": dl_manager.iter_archive(archive)},
 
 
140
  ),
141
  datasets.SplitGenerator(
142
  name=datasets.Split.TEST,
143
  # These kwargs will be passed to _generate_examples
144
+ gen_kwargs={"filepath": paths[self.config.name]["test"], "files": dl_manager.iter_archive(archive)},
 
 
145
  ),
146
  datasets.SplitGenerator(
147
  name=datasets.Split.VALIDATION,
148
  # These kwargs will be passed to _generate_examples
149
+ gen_kwargs={"filepath": paths[self.config.name]["dev"], "files": dl_manager.iter_archive(archive)},
 
 
150
  ),
151
  ]
152
  if self.config.name == "task4_reddit":
 
155
  name=datasets.Split("cand_valid"),
156
  # These kwargs will be passed to _generate_examples
157
  gen_kwargs={
158
+ "filepath": paths[self.config.name]["cand_valid"],
159
+ "files": dl_manager.iter_archive(archive),
160
  },
161
  ),
162
  datasets.SplitGenerator(
163
  name=datasets.Split("cand_test"),
164
  # These kwargs will be passed to _generate_examples
165
  gen_kwargs={
166
+ "filepath": paths[self.config.name]["cand_test"],
167
+ "files": dl_manager.iter_archive(archive),
168
  },
169
  ),
170
  ]
171
  return splits
172
 
173
+ def _generate_examples(self, filepath, files):
174
+ for path, f in files:
175
+ if path == filepath:
176
+ if "cand" not in filepath:
177
+ dialogue_turns = []
178
+ example_idx = 0
179
+ for idx, line in enumerate(f):
180
+ line = line.decode("utf-8")
181
+ if line.strip() == "":
182
+ if dialogue_turns != []:
183
+ yield example_idx, {"dialogue_turns": dialogue_turns}
184
+ example_idx += 1
185
+ dialogue_turns = []
186
+ elif line.strip().split()[0] == "1": # New convo
187
+ if dialogue_turns != []: # Already some convo, flush it out
188
+ yield example_idx, {"dialogue_turns": dialogue_turns}
189
+ example_idx += 1
190
+ dialogue_turns = []
191
+ exchange = line[len(line.split()[0]) :].strip().split("\t") # Skip the number in the front
192
+ sp1 = exchange[0]
193
+ sp2 = exchange[-1] # Might contain multiple tabs in between.
194
+ dialogue_turns.append({"speaker": 0, "utterance": sp1})
195
+ dialogue_turns.append({"speaker": 1, "utterance": sp2})
196
+ else:
197
+ exchange = line[len(line.split()[0]) :].strip().split("\t") # Skip the number in the front
198
+ sp1 = exchange[0]
199
+ sp2 = exchange[-1] # Might contain multiple tabs in between.
200
+ dialogue_turns.append({"speaker": 0, "utterance": sp1})
201
+ dialogue_turns.append({"speaker": 1, "utterance": sp2})
202
+ else:
203
  if dialogue_turns != []:
204
  yield example_idx, {"dialogue_turns": dialogue_turns}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  else:
206
+ dialogue_turns = []
207
+ example_idx = 0
208
+ for idx, line in enumerate(f):
209
+ line = line.decode("utf-8")
210
+ if line.strip() == "":
211
+ if dialogue_turns != []:
212
+ yield example_idx, {"dialogue_turns": dialogue_turns}
213
+ example_idx += 1
214
+ dialogue_turns = []
215
+ elif line.strip().split()[0] == "1": # New convo
216
+ if dialogue_turns != []: # Already some convo, flush it out
217
+ yield example_idx, {"dialogue_turns": dialogue_turns}
218
+ example_idx += 1
219
+ dialogue_turns = []
220
+ exchange = line[len(line.split()[0]) :].strip() # Skip the number in the front
221
+ sp1 = exchange
222
+ dialogue_turns.append({"speaker": 0, "utterance": sp1})
223
+ else:
224
+ exchange = line[len(line.split()[0]) :].strip() # Skip the number in the front
225
+ sp1 = exchange
226
+ dialogue_turns.append({"speaker": 0, "utterance": sp1})
227
+ else: # Last line, new example
228
  if dialogue_turns != []:
229
  yield example_idx, {"dialogue_turns": dialogue_turns}
230
+ break