(self, split)
| 365 | self.tokenizer = tokenizer |
| 366 | |
| 367 | def create_examples(self, split): |
| 368 | if split == "train": |
| 369 | key = "train" |
| 370 | elif split == "dev": |
| 371 | key = "validation" |
| 372 | elif split == "test": |
| 373 | key = "test" |
| 374 | else: |
| 375 | raise NotImplementedError(split) |
| 376 | print_rank_0(f"Creating XSUM-{split} dataset from {self.data_dir}") |
| 377 | with open(os.path.join(self.data_dir, "XSum-TRAINING-DEV-TEST-SPLIT-90-5-5.json")) as file: |
| 378 | id_list = json.load(file) |
| 379 | id_list = id_list[key] |
| 380 | source_texts, target_texts = [], [] |
| 381 | for i, idx in enumerate(id_list): |
| 382 | with open(os.path.join(self.data_dir, f"{idx}.summary")) as file: |
| 383 | key, sentences = None, [] |
| 384 | source_text, target_text = None, None |
| 385 | for line in file: |
| 386 | line = line.strip() |
| 387 | if line.startswith("[SN]"): |
| 388 | if key is not None: |
| 389 | if key == "RESTBODY": |
| 390 | source_text = " ".join(sentences) |
| 391 | elif key == "FIRST-SENTENCE": |
| 392 | target_text = " ".join(sentences) |
| 393 | key = line[4:-4] |
| 394 | sentences = [] |
| 395 | elif line: |
| 396 | sentences.append(line) |
| 397 | if key is not None: |
| 398 | if key == "RESTBODY": |
| 399 | source_text = " ".join(sentences) |
| 400 | elif key == "FIRST-SENTENCE": |
| 401 | target_text = " ".join(sentences) |
| 402 | source_texts.append(source_text) |
| 403 | target_texts.append(target_text) |
| 404 | if (i + 1) % 1000 == 0: |
| 405 | print_rank_0(f"Complete {i + 1} examples") |
| 406 | assert len(source_texts) == len(target_texts) |
| 407 | example_list = [] |
| 408 | for idx, (source_text, target_text) in enumerate(zip(source_texts, target_texts)): |
| 409 | if (idx + 1) % 20000 == 0: |
| 410 | print_rank_0(f"Complete {idx + 1} examples") |
| 411 | guid = "%s-%s" % (split, idx) |
| 412 | meta = {"ref": self.tokenizer.DecodeIds(self.tokenizer.EncodeAsIds(target_text).tokenization)} |
| 413 | example = InputExample(guid=guid, text_a=source_text, text_b=target_text, meta=meta) |
| 414 | if idx < 10: |
| 415 | print_rank_0((source_text.encode('utf-8'), target_text.encode('utf-8'), meta["ref"].encode('utf-8'))) |
| 416 | example_list.append(example) |
| 417 | return example_list |
| 418 | |
| 419 | |
| 420 | class Seq2SeqDataset(torch.utils.data.Dataset): |
nothing calls this directly
no test coverage detected