จาก ep ก่อน ๆ เราจะได้ Training Loop ที่สามารถเทรน Neural Network ได้อย่างถูกต้อง สมบูรณ์ ได้ผลลัพธ์เป็นที่หน้าพอใจ แต่ถ้าเราต้องการเพิ่มเติม Logic การเทรนที่ซับซ้อนยิ่งขึ้น เราจะต้องแก้โค้ดนี้ แทรกตามบรรทัดต่าง ๆ เช่น ก่อนเริ่มเทรน, ก่อนเริ่ม Epoch, หลังจากจบ 1 Epoch, etc.

ข้อเสียของการแทรกโค้ดแบบนี้ คือ ทำให้โค้ดใน Loop นี้ก็จะบวมขึ้นเรื่อย ๆ ส่งผลให้มีปัญหาในการ Maintain แล้วเราจะแก้ปัญหานี้อย่างไรดี

A rotary dial telephone, c. 1940s. Credit https://commons.wikimedia.org/wiki/File:Alt_Telefon.jpg
A rotary dial telephone, c. 1940s. Credit https://commons.wikimedia.org/wiki/File:Alt_Telefon.jpg

Callback

ทางแก้ก็คือ เราจะแทรกโค้ดไว้ก่อนเลยในทุกจุดที่เป็นไปได้ เป็นการ Call Function ภายนอก ที่ตั้งชื่อตาม Event ต่าง ๆ ของ Training Loop

Callback คืออะไร คำอธิบายเพิ่มเติม คลิกที่นี่

เรามาเริ่มกันเลยดีกว่า

Open In Colab

แชร์ให้เพื่อน:

Surapong Kanoktipsatharporn on FacebookSurapong Kanoktipsatharporn on LinkedinSurapong Kanoktipsatharporn on Rss
Surapong Kanoktipsatharporn
Solutions Architect at Bua Labs
The ultimate test of your knowledge is your capacity to convey it to another.

Published by Surapong Kanoktipsatharporn

The ultimate test of your knowledge is your capacity to convey it to another.