ส่วนที่ 2: กำหนดโมเดลแบบเต็ม
รู้หรือไม่ว่าการเทรน Google Neural Machine Translator เวอร์ชันหนึ่งเฉพาะงานแปลภาษาอังกฤษเป็นฝรั่งเศสนั้น ใช้เวลาประมาณ 6 วันและ GPU ถึง 96 ตัว
ในแบบฝึกหัดนี้ คุณจะกำหนดโมเดลแปลภาษาด้วยโครงข่ายประสาทเทียมแบบ encoder-decoder ที่มีความซับซ้อนน้อยกว่ามาก โดยจะนำ input และ output ที่กำหนดไว้ก่อนหน้ามาสร้างออบเจกต์ Keras Model และ compile โมเดลด้วยฟังก์ชัน loss และ optimizer ที่กำหนดให้
ในที่นี้มีตัวแปรที่เตรียมไว้ให้แล้ว ได้แก่ en_inputs (เลเยอร์ input ของ encoder), en_out และ en_state (output ของ encoder GRU), de_out (output ของ decoder GRU) และ de_pred (การพยากรณ์ของ decoder) ซึ่งคุณได้กำหนดไว้ก่อนหน้านี้
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Translation ด้วย Keras
คำแนะนำการฝึกหัด
- กำหนด Keras
Modelโดยรับen_inputsเป็น input และการพยากรณ์ของ decoder (de_pred) เป็น output - Compile โมเดลที่กำหนดโดยเรียกใช้
<model>.compileพร้อมระบุ optimizer เป็น'adam', cross entropy loss และ accuracy (acc) เป็น metric - พิมพ์สรุปโครงสร้างของโมเดล
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
from tensorflow.keras.models import Model
# Define a model with encoder input and decoder output
nmt = ____(____=____, outputs=____)
# Compile the model with an optimizer and a loss
nmt.____(optimizer=____, ____='categorical_crossentropy', metrics=[____])
# View the summary of the model
nmt.____()