Keras 模型
在本练习中,您将练习使用 keras.models 模块中的两个类。您会用 Sequential 类创建一个模型,并用 Model 类创建另一个模型。
Sequential 类更易于使用,因为各层按顺序堆叠;而 Model 类更灵活,支持多输入、多输出以及共享层(共享权重)。
使用 Model 类时需要显式声明输入层;而在 Sequential 类中,则通过 input_shape 参数完成。
环境中已预先加载了 Sequential、Model、Dense、Input、LSTM 和 np(numpy)等对象与模块。
本练习是课程的一部分
使用 Keras 构建语言建模的循环神经网络(RNN)
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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.____