Get startedGet started for free

Keras models

In this exercise you'll practice using two classes from the keras.models module. You will create one model using the Sequential class and another model with the Model class.

The Sequential class is easier to use because the layers are assumed to be in order, while the Model class is more flexible and allows multiple inputs, multiple outputs and shared layers (shared weights).

The Model class needs to explicitly declare the input layer, while in the Sequential class, this is done with the input_shape parameter.

The objects and modules Sequential, Model, Dense, Input, LSTM and np (numpy) are already loaded on the environment.

This exercise is part of the course

Recurrent Neural Networks (RNNs) for Language Modeling with Keras

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Instantiate the class
model = ____(name="sequential_model")

# One LSTM layer (defining the input shape because it is the 
# initial layer)
model.add(____(128, input_shape=(None, 10), name="LSTM"))

# Add a dense layer with one unit
model.add(____(1, activation="sigmoid", name="output"))

# The summary shows the layers and the number of parameters 
# that will be trained
model.____
Edit and Run Code