0
$\begingroup$

I'm struggling with my neural network.

In short, I need to recreate a model from anywhere on the internet, I've found a model that combines BiLSTM, LSTM and GRU. However, based on the error I got when trying to train the model, I suspect that I need to add Flatten layer before Dense layer. But I don't understand what size I should put into this layer, because when I simply add Flatten() before first Dense layer, I get: ValueError: The last dimension of the inputs to a Dense layer should be defined. Found None. Full input shape received: (None, None)

The NN without Flatten() is below.

enter image description here

$\endgroup$

1 Answer 1

0
$\begingroup$

I tried this code and it worked fine without any errors :

model = Sequential()


model.add(Embedding(input_dim = vocab_len,output_dim=emb_dim, trainable = False))
model.add(Bidirectional(LSTM(100,return_sequences=True)))
model.add(Dropout(.2))
model.add(LSTM(100,return_sequences=True))
model.add(Dropout(.2))
model.add(Flatten())
model.add(Dense(60))
model.add(Dense(6,activation = 'softmax'))

optimizer = tf.keras.optimizers.Adam(learning_rate = 0.01)
model.compile(loss = 'sparse_categorical_crossentropy',optimizer=optimizer,metrics=['acucracy'])
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.