How to adjust hyperparameter to improve the training accuracy to 90%?

I was using:

model = tf.keras.Sequential([

    tf.keras.layers.Embedding(num_words, embedding_dim,input_length=maxlen),


    tf.keras.layers.Dense(5, activation='softmax'),

    tf.keras.layers.Dense(1, activation='sigmoid')])




Hello @Alyssa_Sha, Welcome to the community.

Please read carefully the provided instructions in the assignment:

A couple of things to keep in mind:

  • Notice that this function has three parameters, all of which are meant to be passed to an Embedding layer, which is what you will probably use as a first layer for your model.

  • The last layer should be a Dense layer with 5 units (since there are 5 categories) with a softmax activation.

  • You should also compile your model using an appropiate loss function and optimizer.

  • You can use any architecture you want but keep in mind that this problem doesn’t need many layers to be solved successfully. You don’t need any layers besides Embedding, GlobalAveragePooling1D and Dense layers but feel free to try out different architectures.

  • To pass this graded function your model should reach at least a 95% training accuracy and a 90% validation accuracy in under 30 epochs.

Pay attention to the last layer, and if a simple DNN does not do the job consider adding a GlobalAveragePooling1D.