فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة 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
اختبار قصير
اختبر فهمك
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)
for lr in (0.9, 1.05):
w = 1.0
for step in range(10):
w -= lr * 2 * w
print(lr, round(w, 3))
Output
0.9 0.107 1.05 2.594
التمرين 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)
import numpy as np h = np.array([2.0, 4.0, 6.0, 8.0]) print(np.round((h - h.mean()) / h.std(), 2))
Output
[-1.34 -0.45 0.45 1.34]
مشروع صغير في آخر المحاضرة
ابحث عن أحسن 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
الخطوات
- حمّل wine، اقسم ٧٠/٣٠ بـ stratify، واعمل standardization من الـ train.
- جرّب learning_rate_init = 0.0001 و0.001 و0.01 و0.1 و1.
- درّب MLPClassifier((16,), max_iter=200, random_state=0) لكل قيمة.
- اطبع دقة الـ 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 فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.
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.