我在 csv 中有数据。我使用 read_csv 从 csv 获取数据,然后为 DistilBERT 预处理文本 - 标记化,然后填充:
train_csv = pd.read_csv(train_csv)
train_df = train_csv[["text", "label"]]
BATCH_SIZE = 256
tokenized = train_df["text"].apply((lambda x:tokenizer.encode(x, add_special_tokens=True)))
padded = tf.keras.preprocessing.sequence.pad_sequences(tokenized.values, padding="post", maxlen=512)
attention_mask = np.where(padded != 0, 1, 0)
input_ids = torch.tensor(padded)
attention_mask = torch.tensor(attention_mask)
with torch.no_grad():
last_hidden_states = model(input_ids, attention_mask=attention_mask)
在执行最后一步时,我遇到了 RAM 内存问题。有人可以分享如何批量处理它并获得最后一个隐藏状态吗?
谢谢你。