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

الفصل 4 (الجزء 1): Training Practice

Overfitting, validation sets and weight decay

على طول: إزاي نعرف إن الشبكة بتحفظ بدل ما تفهم، وإزاي نعالج ده.

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

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

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

رسوم متحركة

نموذج بسيط مقابل معقّد
الـ loss وهو بينزل

أمثلة Python

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

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

المثال ١: فجوة الـ train والـ test

Sample output (press Run to produce your own):
train: 0.99  test: 0.73

المثال ٢: حجم الشبكة والـ validation

Sample output (press Run to produce your own):
hidden 1 train 0.54 val 0.39
hidden 4 train 0.84 val 0.81
hidden 16 train 0.84 val 0.83
hidden 128 train 0.94 val 0.95

المثال ٣: الـ weight decay

Sample output (press Run to produce your own):
alpha 0 train 0.99 test 0.73
alpha 0.01 train 0.99 test 0.77
alpha 0.1 train 0.97 test 0.8
alpha 1 train 0.84 test 0.83

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

اختبار قصير

اختبر فهمك

1. Low training error but much higher validation error signals:

2. The test set should be used:

3. Which one helps against overfitting?

4. Weight decay pushes the weights:

5. Underfitting means:

تمارين برمجة

جرّب بإيدك

التمرين 1

درّب MLP بـ hidden (1,) على make_moons (400, noise 0.2) واطبع دقة الـ train والـ test (underfitting).

Train an MLP with hidden (1,) on make_moons (400, noise 0.2). Print train and test accuracy (underfitting).

(output appears here)

التمرين 2

طبّق weight decay يدوي: w = w * (1 - lr * alpha) على w = [1, -2, 3] بـ lr = 0.1 و alpha = 0.5 لـ 10 خطوات واطبع w.

Apply manual weight decay w = w * (1 - lr * alpha) to w = [1, -2, 3], lr = 0.1, alpha = 0.5, for 10 steps. Print w.

(output appears here)

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

اضبط حجم الشبكة والـ weight decay على الـ validation

الداتا: Breast Cancer Wisconsin (Diagnostic): 569 samples, 30 features, benign or malignant. Source: UCI Machine Learning Repository.

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

الخطوات

  1. قسّم الداتا train / validation / test بنسب ٦٠/٢٠/٢٠ (random_state=0) واعمل standardization من الـ train.
  2. جرّب hidden (4,) و(64,) و(64, 64) مع alpha = 0 و1.
  3. اختار أحسن إعداد على الـ validation.
  4. اطبع دقة الـ test لإعداد واحد بس: اللي اخترته.
Expected output (press Run to produce your own):
hidden (4,)     alpha 0 val 0.956
hidden (4,)     alpha 1 val 0.956
hidden (64,)    alpha 0 val 0.956
hidden (64,)    alpha 1 val 0.956
hidden (64, 64) alpha 0 val 0.956
hidden (64, 64) alpha 1 val 0.956
test accuracy of the chosen setting: 0.956

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, Generalization in Deep Learning and Weight Decay.