定義 Teacher Forcing 模型
所有層都已建立後,下一步要定義一個 Keras 的 Model 物件。這個模型和你先前定義的稍有不同,因為新模型有兩個輸入層。
你已經拿到上一個練習實作的 Keras 層,包括 en_inputs、en_gru、de_inputs、de_gru 和 de_pred。
本練習屬於課程
使用 Keras 進行機器翻譯
練習說明
- 從
models子模組匯入 Keras 的Model物件。 - 定義一個模型,依序以編碼器輸入層與解碼器輸入層作為輸入,並輸出最終的預測結果。
- 使用最佳化器
adam與損失函式categorical_crossentropy編譯模型。 - 列印模型摘要。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the Keras Model object
from tensorflow.keras.____ import ____
# Define a model
nmt_tf = ____(inputs=[____, ____], outputs=____)
# Compile the model with optimizer and loss
nmt_tf.compile(optimizer=____, ____=____, metrics=["acc"])
# Print the summary of the model
nmt_tf.____()