I have tried LSTM, Conv1D with Dropout, Regularization, Normalization, GlobalAvgeragePooling1D and GlobalMaxPooling1D but nothing seems to work. Assistance required. The model code is below
def create_model(vocab_size, embedding_dim, maxlen, embeddings_matrix):
"""
Creates a binary sentiment classifier model
Args:
vocab_size (int): size of the vocabulary for the Embedding layer input
embedding_dim (int): dimensionality of the Embedding layer output
maxlen (int): length of the input sequences
embeddings_matrix (array): predefined weights of the embeddings
Returns:
model (tf.keras Model): the sentiment classifier model
"""
### START CODE HERE
model = tf.keras.Sequential([
# This is how you need to set the Embedding layer when using pre-trained embeddings
tf.keras.layers.Embedding(vocab_size+1, embedding_dim, input_length=maxlen, weights=[embeddings_matrix], trainable=False),
tf.keras.layers.Bidirectional(tf.keras.layers.GRU(32)),
# tf.keras.layers.Conv1D(128, 5, activation = "relu"),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Dropout(0.5),
# tf.keras.layers.GlobalAveragePooling1D(),
tf.keras.layers.Dense(64, activation = "relu"),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(1, activation = "sigmoid")
])
model.compile(loss="binary_crossentropy",
optimizer="Adam",
metrics=['accuracy'])
### END CODE HERE
return model
# Create your untrained model
model = create_model(VOCAB_SIZE, EMBEDDING_DIM, MAXLEN, EMBEDDINGS_MATRIX)
# Train the model and save the training history
history = model.fit(train_pad_trunc_seq, train_labels, epochs=20, validation_data=(val_pad_trunc_seq, val_labels))