Tensorflow error: ValueError: Shapes (128, 100) and (128, 100, 139) are incompatible

I try to use Functional API for my model, but i don't understand why i have error:

ValueError: Shapes (128, 100) and (128, 100, 139) are incompatible

My code:

input_tensor = Input(batch_input_shape=(batch_size,None))
x = Embedding(vocab_size, embed_dim)(input_tensor)
x = LSTM(rnn_neurons4, return_sequences=True, stateful=True)(x)
output_tensor = Dense(vocab_size, activation='softmax')(x)
model = Model(input_tensor, output_tensor) 

model.summary()

Adam = tf.keras.optimizers.Adam(learning_rate=0.0001)
model.compile(optimizer=Adam, loss="categorical_crossentropy", metrics=['accuracy'])

model summory

fit code:

epochs = 1000
early_stop = EarlyStopping(monitor='loss', patience=25)
try:
  model.fit(dataset,epochs=epochs, callbacks=[early_stop])
  model.save('train.h5')
except KeyboardInterrupt:
  model.save('train.h5')

1 answer

  • answered 2022-05-04 11:03 Артем Голуб

    I don't know this is correct way or not.

    I create my own function with sparse_categorical_crossential and add in model.compile

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum