【发布时间】:2018-09-21 11:43:07
【问题描述】:
我正在尝试从带注释的文本中找出与单词相关的标签。我正在使用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 模型所需的适当维度。
【问题讨论】:
-
我不了解您的模型数据。 sequence_length 和 n_words 的值是多少。你能添加model.summary()的输出吗?但无论如何,您的输出将大小为 50(最后一层的大小)。
标签: keras lstm rnn named-entity-extraction