我正在尝试从带注释的文本中找出与单词相关的标签。我正在使用一个bidirectional LSTM
. 我有X_train
它的形状(1676, 39)和Y_train
相同的形状(1676, 39)。
input = Input(shape=(sequence_length,))
model = Embedding(input_dim=n_words, output_dim=20,
input_length=sequence_length, mask_zero=True)(input)
model = Bidirectional(LSTM(units=50, return_sequences=True,
recurrent_dropout=0.1))(model)
out_model = TimeDistributed(Dense(50, activation="softmax"))(model)
model = Model(input, out_model)
model.compile(optimizer="rmsprop", loss= "categorical_crossentropy", metrics=["accuracy"])
model.fit(X_train, Y_train, batch_size=32, epochs= 10,
validation_split=0.1)
执行此操作时,我收到错误:
ValueError: Error when checking target: expected time_distributed_5 to have 3 dimensions, but got array with shape (1676, 39).
我无法找出如何提供 Keras LSTM 模型所需的适当尺寸。