将错误视为值错误,如果收到此错误我该怎么办

问题描述 投票:0回答:1

F.softmax(模型(input_ids,attention_mask),dim = 1) 错误是 在处理 keras 功能模型的输入张量时发现意外实例。期望来自 tf.keras.Input() 的 KerasTensor 或来自 keras 层 call() 的输出。得到:张量([[ 101, 1192, 1169, ..., 0, 0, 0], [ 101, 146, 3983, ..., 0, 0, 0], [ 101, 122, 119, ..., 17424, 28404, 102], ..., [ 101, 2543, 3014, ..., 0, 0, 0], [ 101, 1960, 1614, ..., 0, 0, 0], [ 101, 138, 8661, ..., 0, 0, 0]])

python softmax collaboration
1个回答
0
投票

您似乎在代码中混合了 PyTorch 和 TensorFlow 语法。 F.softmax() 来自 PyTorch 库,而您收到的错误消息表明您正在尝试使用 Keras (TensorFlow) 模型。

如果您使用 TensorFlow/Keras:

from tensorflow.keras import layers

model = keras.models.Sequential()
model.add(layers.Dense(64, activation='relu')) 
model.add(layers.Dense(10, activation='softmax'))   
© www.soinside.com 2019 - 2024. All rights reserved.