keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.89k stars 19.45k forks source link

How can i decide that the model is best fit with this settings ? #14943

Closed ersamo closed 3 years ago

ersamo commented 3 years ago
def define_model(vocab_size, max_length, curr_shape):
    inputs1 = Input(shape=curr_shape)
    fe1 = Dropout(0.5)(inputs1)
    fe2 = Dense(256, activation='relu')(fe1)
    model = tf.keras.models.Sequential()
    inputs2 = Input(shape=(max_length,))
    se1 = Embedding(vocab_size, 256, mask_zero=True)(inputs2)
    se2 = Dropout(0.5)(se1)
    se3 = LSTM(256)(se2)
    decoder1 =Concatenate()([fe2, se3])
    decoder2 = Dense(256, activation='relu')(decoder1)
    outputs = Dense(vocab_size, activation='softmax')(decoder2)
    model = Model(inputs=[inputs1, inputs2], outputs=outputs)
    model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])
    model.summary()
    return model

the model as follows

Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_2 (InputLayer)            [(None, 49)]         0                                            
__________________________________________________________________________________________________
input_1 (InputLayer)            [(None, 1120)]       0                                            
__________________________________________________________________________________________________
embedding (Embedding)           (None, 49, 256)      6235648     input_2[0][0]                    
__________________________________________________________________________________________________
dropout (Dropout)               (None, 1120)         0           input_1[0][0]                    
__________________________________________________________________________________________________
dropout_1 (Dropout)             (None, 49, 256)      0           embedding[0][0]                  
__________________________________________________________________________________________________
dense (Dense)                   (None, 256)          286976      dropout[0][0]                    
__________________________________________________________________________________________________
lstm (LSTM)                     (None, 256)          525312      dropout_1[0][0]                  
__________________________________________________________________________________________________
concatenate (Concatenate)       (None, 512)          0           dense[0][0]                      
                                                                 lstm[0][0]                       
__________________________________________________________________________________________________
dense_1 (Dense)                 (None, 256)          131328      concatenate[0][0]                
__________________________________________________________________________________________________
dense_2 (Dense)                 (None, 24358)        6260006     dense_1[0][0]     

i set history = model.fit(train_generator, epochs=20, steps_per_epoch=train_steps, verbose=1, callbacks=[checkpoint], validation_data=val_generator, validation_steps=val_steps,batch_size=16)

and got

loss: 4.7179 - accuracy: 0.2422 - val_loss: 4.2133 - val_accuracy: 0.2912
loss: 4.1017 - accuracy: 0.3009 - val_loss: 3.9599 - val_accuracy: 0.3136 
loss: 3.9611 - accuracy: 0.3131 - val_loss: 3.8945 - val_accuracy: 0.3202

training set is 82700 and testing is 40500 .. Should i wait until i got the lower val_loss ? or what the factors that should i take to decide that model best fit ? i run it before and got at epoch 6 that there is no improvement .. is there any problem in the model ? Should i increase epochs to 70 instead of 20 ?

ersamo commented 3 years ago

is there any help please ?

rafiqhasan commented 3 years ago

Better suited for stackoverflow

namaannn commented 3 years ago

@ersamo try tuning the layers and hyperparameters using keras tuner

jvishnuvardhan commented 3 years ago

@ersamo This is not Build/Installation or Bug/Performance issue. Please post this kind of support questions at TF Forum. There is a big community to support and learn from your questions. GitHub is mainly for addressing bugs in installation and performance. Thanks!

Looking at your model, i think you may need to add some more hidden layers, change some hyper parameters, tune the model, check the diversity in the input data, etc. I am sure, you will get much more support from TF Forum. Thanks!