الرئيسية / مقرر Deep Learning / الفصل 5 الجزء 2

الفصل 5 (الجزء 2): Optimization

Learning rate, schedules and normalization

على طول: أهم إعداد في التدريب، والـ normalization اللي بيسهّله.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

رسوم متحركة

أثر الـ learning rate

أمثلة Python

أمثلة قصيرة وبسيطة

الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.

المثال ١: ثلاث قيم للـ learning rate

Sample output (press Run to produce your own):
lr 0.01 -> w after 20 steps: 3.34
lr 0.4 -> w after 20 steps: 5.24e-14
lr 1.1 -> w after 20 steps: 192.0

المثال ٢: Step decay

Sample output (press Run to produce your own):
epoch 0 learning rate 0.4
epoch 5 learning rate 0.4
epoch 10 learning rate 0.2
epoch 15 learning rate 0.2
epoch 20 learning rate 0.1
epoch 25 learning rate 0.1

المثال ٣: أثر الـ standardization

Sample output (press Run to produce your own):
raw           test accuracy: 0.258
standardized  test accuracy: 0.944

افتح الفصل المقابل في كتاب d2l.ai

اختبار قصير

اختبر فهمك

1. A learning rate that is too large usually makes the loss:

2. Why decay the learning rate over time?

3. Standardization statistics should be computed on:

4. Batch normalization normalizes each hidden unit over:

5. If the loss becomes NaN, first try:

تمارين برمجة

جرّب بإيدك

التمرين 1

جرّب lr = 0.9 و lr = 1.05 على f(w) = w^2 من w = 1 لـ 10 خطوات واطبع w لكل واحد.

Try lr = 0.9 and lr = 1.05 on f(w) = w^2 from w = 1 for 10 steps. Print w for each.

(output appears here)

التمرين 2

اعمل batch normalization يدوي لعمود أرقام [2, 4, 6, 8] (متوسط صفر وانحراف ١) واطبعه.

Hand-normalize the column [2, 4, 6, 8] (mean 0, std 1) and print it.

(output appears here)

مشروع صغير في آخر المحاضرة

ابحث عن أحسن learning rate على الـ wine

الداتا: Wine recognition dataset: 178 samples, 13 chemical features, 3 cultivars. Source: UCI Machine Learning Repository.

License / source: Ships with scikit-learn. Dataset page

الخطوات

  1. حمّل wine، اقسم ٧٠/٣٠ بـ stratify، واعمل standardization من الـ train.
  2. جرّب learning_rate_init = 0.0001 و0.001 و0.01 و0.1 و1.
  3. درّب MLPClassifier((16,), max_iter=200, random_state=0) لكل قيمة.
  4. اطبع دقة الـ validation (٥-fold على الـ train) واختار أحسن قيمة.
Expected output (press Run to produce your own):
lr 0.0001 cv accuracy 0.419
lr 0.001 cv accuracy 0.944
lr 0.01 cv accuracy 0.968
lr 0.1 cv accuracy 0.96
lr 1 cv accuracy 0.928

مشروع نهاية الفصل

ملف المشروع العملي للفصل 5

ملف PDF فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.

افتح ملف المشروع (PDF)

Credits: the topic order follows the book "Dive into Deep Learning" (d2l.ai) by Zhang, Lipton, Li and Smola, whose text is licensed CC BY-SA 4.0. The explanations, diagrams and code in this lecture are our own and are not copied from the book. Reference: d2l.ai, Learning Rate Scheduling and Batch Normalization.