尝试对数据进行标记和编码以提供给神经网络。
我只有 25GB 的 RAM,每次我尝试在我的 google colab 崩溃下运行代码时。知道如何防止他的发生吗?“您的会话在使用所有可用 RAM 后崩溃”</p>
我认为标记/编码 50000 个句子的块会起作用,但不幸的是没有。该代码适用于长度为 130 万的数据集。当前数据集的长度为 500 万。
max_q_len = 128
max_a_len = 64
trainq_list = train_q.tolist()
batch_size = 50000
def batch_encode(text, max_seq_len):
for i in range(0, len(trainq_list), batch_size):
encoded_sent = tokenizer.batch_encode_plus(
text,
max_length = max_seq_len,
pad_to_max_length=True,
truncation=True,
return_token_type_ids=False
)
return encoded_sent
# tokenize and encode sequences in the training set
tokensq_train = batch_encode(trainq_list, max_q_len)
分词器来自 HuggingFace:
tokenizer = BertTokenizerFast.from_pretrained('bert-base-multilingual-uncased')