getting the error as value error , what should i do if i get this error

46 Views Asked by At

F.softmax(Model(input_ids, attention_mask), dim=1) and the error is Found unexpected instance while processing input tensors for keras functional model. Expecting KerasTensor which is from tf.keras.Input() or output from keras layer call(). Got: tensor([[ 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]])

1

There are 1 best solutions below

1
Suprava On

It seems you're mixing PyTorch and TensorFlow syntax in your code. F.softmax() is from the PyTorch library, while the error message you're getting suggests that you're trying to use a Keras (TensorFlow) model.

If you're using 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'))