ValueError:lstm_34层的输入0与该层不兼容:预期ndim = 3,找到的ndim = 2。收到完整的形状:[无,25]

时间:2020-09-04 22:59:42

标签: tensorflow keras lstm stanford-nlp embedding

我是lstm的新手,任何人都可以解释为什么我遇到此错误吗?

我的lstm模型-

def NNStructure():

input_text = tf.keras.Input((), dtype = tf.string, name = 'input_text')
initial_input= Embedding(vocab_size, 25, weights= 
[embedding_matrix], input_length=50,trainable=False) (input_text)

lstm = LSTM(32, input_shape=(50,25))(initial_input)  
secondary_input = Input(shape=(50,6))    
merge = concatenate([lstm, secondary_input])(lstm)
first_dense = Dense(128, activation='relu')(merge)
second_dense=Dense(64, activation='relu')(first_dense)
output=Dense(1, activation='sigmoid')(second_dense)

model_glove1 = Model(inputs=[initial_input, secondary_input], outputs=output)
return model_glove1

model_glove1 = NNStructure() model_glove1.compile(loss ='binary_crossentropy',optimizer ='adam',metrics = ['accuracy']) model_glove1.fit(x = [pad_seq,X_meta_train],y = np.array(Y_train),batch_size = 32,epochs = 4,verbose = 1,validation_split = 0.2,shuffle = True)

0 个答案:

没有答案