[英]Tensorflow RNN Model Shapes are Incompatible Error
我正在尝试在一些文本数据上训练 RNN 分类器。
事实:
ValueError: Shapes (None, 1) and (None, 32) are incompatible
问题:
为什么我会在这个模型的任何地方得到 1 的形状? 有什么我遗漏的吗?
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)
问题肯定出在数据集中:(None, 32) 是模型输出的形状,而 (None, 1) 是提供的 y_indexes 变量的形状。
也许您实际上并没有对标签进行一次性编码,在这种情况下,只需这样做或使用 SparseCategoricalCrossentropy() 作为损失函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.