Hi
I got a problem when i want to compile my nlp model using keras on google colab.
here is my code :
model = Sequential()
model.add(Embedding(input_dim=len(tokenizer.word_index) + 1, output_dim=128, input_length=max_length))
model.add(LSTM(128, return_sequences=True))
model.add(LSTM(64)) # Dernière LSTM sans return_sequences
model.add(Dropout(0.2))
model.add(Dense(82, activation=‘relu’))
model.add(Dense(7, activation=‘softmax’))
model.compile(optimizer=optimizer, loss=‘categorical_crossentropy’, metrics=[‘accuracy’])
model.summary()
but the output is :
could you please assit me and tell me what is the error ?
Thanks in advance
Hi @Nicolas_Orefice, This happens when input shape is not defined. In the first layer
you have not defined the input_shape so model.summary does not provide the output shape.
If you provide the input shape
model = Sequential()
model.add(Embedding(input_dim=786, output_dim=128, input_length=64,input_shape=(64,)))
model.add(LSTM(128, return_sequences=True))
model.add(LSTM(64)) # Dernière LSTM sans return_sequences
model.add(Dropout(0.2))
model.add(Dense(82, activation='relu'))
model.add(Dense(7, activation='softmax'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
then the model summary will generate the output shape based on the input shape
model.summary()
Model: "sequential_2"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type) ┃ Output Shape ┃ Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ embedding_2 (Embedding) │ (None, 64, 128) │ 100,608 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ lstm_2 (LSTM) │ (None, 64, 128) │ 131,584 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ lstm_3 (LSTM) │ (None, 64) │ 49,408 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dropout_1 (Dropout) │ (None, 64) │ 0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense_2 (Dense) │ (None, 82) │ 5,330 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense_3 (Dense) │ (None, 7) │ 581 │
└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
Total params: 287,511 (1.10 MB)
Trainable params: 287,511 (1.10 MB)
Non-trainable params: 0 (0.00 B)
Thank You.