Your first RNN model
In this exercise you will put in practice the Keras modules to build your first RNN model and use it to classify sentiment on movie reviews.
This first model has one recurrent layer with the vanilla RNN cell: SimpleRNN, and the output layer with two possible values: 0 representing negative sentiment and 1 representing positive sentiment.
You will use the IMDB dataset contained in keras.datasets. A model was already trained and its weights stored in the file model_weights.h5. You will build the model's architecture and use the pre-loaded variables x_test and y_test to check the its performance.
Este ejercicio forma parte del curso
Recurrent Neural Networks (RNNs) for Language Modeling with Keras
Instrucciones del ejercicio
- Add the
SimpleRNNcell with128units. - Add a
Denselayer with one unit for sentiment classification. - Use the proper loss function for binary classification.
- Evaluate the model on the pre-trained validation set:
(x_test, y_test).
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Build model
model = Sequential()
model.add(____(units=____, input_shape=(None, 1)))
model.add(Dense(____, activation='sigmoid'))
model.compile(loss='____',
optimizer='adam',
metrics=['accuracy'])
# Load pre-trained weights
model.load_weights('model_weights.h5')
# Method '.evaluate()' shows the loss and accuracy
loss, acc = model.evaluate(____, ____, verbose=0)
print("Loss: {0} \nAccuracy: {1}".format(loss, acc))