'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'])
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')
Solution 1:[1]
I create my own function with sparse_categorical_crossential and add in model.compile
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Matt Andruff |