I'm trying to train a RNN classifier over some text data.
Facts:
ValueError: Shapes (None, 1) and (None, 32) are incompatible
Question:
Why would I get the shape of 1 anywhere in this model? Is there something that I omitted?
model = tf.keras.Sequential([
train_encoder,
tf.keras.layers.Embedding(
input_dim=len(train_encoder.get_vocabulary()),
output_dim=64,
mask_zero=True),
tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(64)),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(32, activation='softmax')
])
model.compile(loss=tf.keras.losses.CategoricalCrossentropy(),
optimizer=tf.keras.optimizers.Adam(1e-4),
metrics=['accuracy'])
model.fit(x, y_indexes, epochs=50, verbose=2, validation_split=0.1)
The issue is definitely in the dataset: (None, 32) is the shape of the model output, while (None, 1) is the shape of the provided y_indexes variable.
Perhaps you didn't actually one-hot encoded the labels, in which case just do it or use SparseCategoricalCrossentropy() as the loss function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.