การเชื่อมโยงระหว่างโมเดลที่ฝึกแล้วกับโมเดล Inference
ในแบบฝึกหัดนี้ จะทำการถ่ายโอนน้ำหนักที่ฝึกแล้วจากโมเดลที่ฝึกไปยังโมเดล inference ในโมเดล encoder-decoder มี layer ที่มีพารามิเตอร์อยู่ 3 layer ได้แก่
- Layer
GRUของ encoder - Layer
GRUของ decoder - Layer
Denseของ decoder
ส่วน layer อื่น ๆ เช่น TimeDistributed ไม่มีพารามิเตอร์ จึงไม่จำเป็นต้องคัดลอกน้ำหนัก
สำหรับแบบฝึกหัดนี้ มีการเตรียม layer GRU ของ encoder ที่ฝึกแล้ว (tr_en_gru), layer GRU ของ decoder ที่ฝึกแล้ว (tr_de_gru) และ layer Dense ที่ฝึกแล้ว (tr_de_dense) ไว้ให้แล้ว นอกจากนี้ยังเข้าถึง layer ทั้งหมดของโมเดล inference ได้ด้วย ไม่ว่าจะเป็น layer GRU ของ encoder (en_gru), layer GRU ของ decoder (de_gru) และ layer Dense (de_dense)
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Translation ด้วย Keras
คำแนะนำการฝึกหัด
- โหลดน้ำหนักของ layer
GRUของ encoder ที่ฝึกแล้ว - กำหนดน้ำหนักให้กับ layer
GRUของ encoder ในโมเดล inference - โหลดน้ำหนักของ layer
GRUของ decoder (ที่ฝึกแล้ว) และกำหนดน้ำหนักในโมเดล inference - โหลดน้ำหนักของ layer
Denseของ decoder (ที่ฝึกแล้ว) และกำหนดน้ำหนักในโมเดล inference
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Load the weights to the encoder GRU from the trained model
en_gru_w = ____.get_weights()
# Set the weights of the encoder GRU of the inference model
en_gru.____(____)
# Load and set the weights to the decoder GRU
de_gru.____(tr_de_gru.____)
# Load and set the weights to the decoder Dense
____.set_weights(____.____)