使用 CNN 層
在這個練習中,你會使用一個預先訓練的模型。它使用 keras.layers.convolutional 模組中的 Conv1D 與 MaxPooling1D 層,並在分類任務上達到更高的準確率。
這個架構在像是分類這類的語言建模任務上有不錯的表現。這裡把它當作額外練習,讓你看看實際效果並建立一些直覺。
由於這個層不在本課程的範圍內,你將著重於如何把它和你已經學過的 RNN 層一起使用。
請依照說明操作以查看結果。
本練習屬於課程
使用 Keras 建立語言模型的循環神經網路(RNN)
練習說明
- 列印模型架構。
- 載入預先訓練的權重。
- 在測試資料上評估模型。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the model summary
model_cnn.____
# Load pre-trained weights
model_cnn.____('model_weights.h5')
# Evaluate the model to get the loss and accuracy values
loss, acc = ____(x_test, y_test, verbose=0)
# Print the loss and accuracy obtained
print("Loss: {0}\nAccuracy: {1}".format(loss, acc))