Search code examples
pythonkeraslstmtext-classification

What does a "None" mean after compilation of keras model?


I'm trying to implement a binary text classification model using keras layers. After compiling a model, in a summary, I am getting None at the bottom end and I don't exactly understand what does it mean?

here is the code which I am using.

max_words = 10000
max_len = 500
tok = Tokenizer(num_words=max_words)
tok.fit_on_texts(X_train)
sequences = tok.texts_to_sequences(X_train)
sequences_matrix = sequence.pad_sequences(sequences,maxlen=max_len)

model = Sequential()
model.add(Embedding(max_words, 50, input_length=max_len))
model.add(LSTM(64))
model.add(Dense(256,name='FC1',activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics= 
             ['acc'])
print(model.summary())

This is the model summary and at the bottom end It is showing None.

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
embedding_1 (Embedding)      (None, 500, 50)           500000    
_________________________________________________________________
lstm_1 (LSTM)                (None, 64)                29440     
_________________________________________________________________
FC1 (Dense)                  (None, 256)               16640     
_________________________________________________________________
dropout_1 (Dropout)          (None, 256)               0         
_________________________________________________________________
dense_1 (Dense)              (None, 1)                 257       
=================================================================
Total params: 546,337
Trainable params: 546,337
Non-trainable params: 0
_________________________________________________________________
None

Solution

  • model.summary() returns nothing (None), and you are printing the return value of it. model.summary() already does the printing internally, there is no need to get confused with printing it manually, so just do:

    model.summary()