1

私は 16 GB の大きさのコーパスを持っており、RAM は約 16 GB です。データセット全体を読み込んで言語モデル RoBERTa をゼロからトレーニングすると、メモリの問題が発生します。Huggingface のブログ記事 ( https://colab.research.google.com/github/huggingface/blog/blob/master/notebooks/01_how_to_train.ipynb ) で提供されているスクリプトを使用して、RoBERTa をトレーニングするつもりです。

ただし、彼らのブログ投稿では、LineByLineTextDatase の使用が提案されています。ただし、これはデータセットを熱心に読み込みます。

class LineByLineTextDataset(Dataset):
    """
    This will be superseded by a framework-agnostic approach
    soon.
    """

    def __init__(self, tokenizer: PreTrainedTokenizer, file_path: str, block_size: int):
        assert os.path.isfile(file_path)
        # Here, we do not cache the features, operating under the assumption
        # that we will soon use fast multithreaded tokenizers from the
        # `tokenizers` repo everywhere =)
        logger.info("Creating features from dataset file at %s", file_path)

        with open(file_path, encoding="utf-8") as f:
            lines = [line for line in f.read().splitlines() if (len(line) > 0 and not line.isspace())]

        batch_encoding = tokenizer(lines, add_special_tokens=True, truncation=True, max_length=block_size)
        self.examples = batch_encoding["input_ids"]

    def __len__(self):
        return len(self.examples)

    def __getitem__(self, i) -> torch.Tensor:
        return torch.tensor(self.examples[i], dtype=torch.long)

予期せぬことに、私のカーネルは行を読み取った部分でクラッシュしました。怠惰に読ませる方法はないのだろうか。私はHuggingfaceを初めて使用し、自分でデバッグできないのではないかと心配しているため、投稿されたチュートリアルで提案された回答が最小限のコード変更を作成できる場合、それは非常に望ましいことです。

4

1 に答える 1