開始使用免費開始

Keras 模型

在這個練習中,你會練習使用 keras.models 模組裡的兩個類別。你將用 Sequential 類別建立一個模型,並用 Model 類別再建立另一個模型。

Sequential 類別較容易使用,因為各層會依序堆疊;相對地,Model 類別更有彈性,允許多個輸入、多個輸出,以及共用層(共用權重)。

使用 Model 類別時需要明確宣告輸入層;而在 Sequential 類別中,則透過 input_shape 參數來完成。

環境中已經載入物件與模組 SequentialModelDenseInputLSTM 以及 npnumpy)。

本練習屬於課程

使用 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.____
編輯並執行程式碼