Tensorflow 2.0如何批量处理数据

问题描述

我有 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 内存问题。有人可以分享如何批量处理并获得最后的隐藏状态吗?

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)