เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การฝึกโมเดล

รู้หรือไม่ว่าในปี 2017 Google Translate มีผู้ใช้งานมากกว่า 500 ล้านคนต่อวัน?

ในแบบฝึกหัดนี้ คุณจะได้ฝึกโมเดล Teacher Forcing เป็นครั้งแรก Teacher Forcing เป็นเทคนิคที่นิยมใช้ในโมเดลแบบ sequence to sequence เช่น neural machine translator เพื่อให้ได้ประสิทธิภาพที่ดียิ่งขึ้น

คุณจะได้รับฟังก์ชัน sents2seqs() พร้อมกับประโยคภาษาอังกฤษ en_text และประโยคภาษาฝรั่งเศส fr_text

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Machine Translation ด้วย Keras

ดูคอร์ส

คำแนะนำการฝึกหัด

  • ดึง decoder input ซึ่งประกอบด้วยลำดับที่เข้ารหัสแบบ onehot ของคำภาษาฝรั่งเศส (ยกเว้นคำสุดท้ายในแต่ละลำดับ)
  • ดึง decoder output ซึ่งประกอบด้วยลำดับที่เข้ารหัสแบบ onehot ของคำภาษาฝรั่งเศส (ยกเว้นคำแรกในแต่ละลำดับ)
  • ฝึกโมเดลด้วยข้อมูลชุดเดียว (single batch)
  • คำนวณค่า evaluation metrics (loss และ accuracy) สำหรับข้อมูลฝึก en_x, de_x และ de_y

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

n_epochs, bsize = 3, 250

for ei in range(n_epochs):
  for i in range(0,data_size,bsize):
    en_x = sents2seqs('source', en_text[i:i+bsize], onehot=True, reverse=True)
    de_xy = sents2seqs('target', fr_text[i:i+bsize], onehot=True)
    # Separate the decoder inputs from de_xy
    de_x = ____[:,____,:]
    # Separate the decoder outputs from de_xy
    de_y = ____[____]
    # Train the model on a single batch of data    
    nmt_tf.____([____,____], ____)    
    # Obtain the eval metrics for the training data
    res = _____.evaluate([____,____], ____, batch_size=bsize, verbose=0)
    print("{} => Train Loss:{}, Train Acc: {}".format(ei+1,res[0], res[1]*100.0))  
แก้ไขและรันโค้ด