จาก ep ก่อน เราได้รู้จัก Hyperparameter ที่สำคัญที่สุดในการเทรน Machine Learning ชื่อ Learning Rate แต่ปัญหาคือ ถ้าเรากำหนดค่า Learning น้อยไปก็ทำให้เทรนได้ช้า แต่ถ้ามากเกินไปก็ทำให้ไม่ Converge หรืออาจจะ Error ไปเลย

แล้วเราจะมีวิธีใด ที่จะหาค่า Learning Rate ที่ดีที่สุด มาใช้เทรน Deep Neural Network ของเรา

Learning Rate ที่ดีที่สุด

Learning Rate ที่ดีที่สุด หมายถึง Learning Rate ที่มากที่สุด ที่ไม่ทำให้ Loss แย่ลง ทำให้เทรนโมเดลได้เร็วที่สุด (ในปัจจุบันมักจะมีการใช้เทคนิคอื่น ๆ อีกหลายอย่างเข้ามาช่วยด้วย)

convergence of various learning rates Credit: http://cs231n.github.io/neural-networks-3/
convergence of various learning rates Credit: http://cs231n.github.io/neural-networks-3/

เราจะหาค่า Learning Rate ที่ดีที่สุด ด้วยอัลกอริทึมง่าย ๆ ตรงตัว ดังนี้

LR_Find

lr_find คือ การทดลองเทรนโมเดล Deep Neural Network จาก Learning Rate น้อย ๆ แล้วเพิ่ม Learning Rate ขึ้นไปเรื่อย ๆ ในขณะเดียวกันก็คอยเช็ค Loss ดูว่าน้อยลงเรื่อย ๆ จนกระทั่ง Loss กลับเป็นเพิ่มมากจนผิดปกติ เรียกว่า LR Finder (Learning Rate Finder)

lr_find recorder plot Loss, Learning Rate
lr_find recorder plot Loss, Learning Rate

เมื่อเราได้ข้อมูล ความสัมพันธ์ระหว่าง Learning Rate กับ Loss ของโมเดล Deep Neural Network ของเรามาเรียบร้อยแล้ว เราจะนำมาพล็อตกราฟ เพื่อวิเคราะห์หา Learning Rate ที่ดีที่สุดต่อไป

Learning Rate Techniques

ส่วนเทคนิคประยุกต์ Learning Rate แบบต่าง ๆ เช่น Learning Rate ไม่คงที่, Learning Rate Annealing, Cyclical Learning Rate, การใช้ Learning Rate แตกต่างกันในแต่ละ Layer, etc. จะอธิบายต่อไป

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

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.