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

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

Dropout, initialization and early stopping

على طول: ثلاث أدوات بتخلّي تدريب الشبكات مستقر وبتمنع الـ overfitting.

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

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

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

رسوم متحركة

الـ dropout بيطفّي neurons عشوائياً

أمثلة Python

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

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

المثال ١: الـ dropout بإيدينا

Sample output (press Run to produce your own):
kept mask  : [1 0 0 0 1 1 1 1 1 1]
after drop : [2. 0. 0. 0. 2. 2. 2. 2. 2. 2.]

المثال ٢: حجم الإشارة مع الـ initialization

Sample output (press Run to produce your own):
too small  std after 10 layers: 3.1e-12
too big    std after 10 layers: 369000000.0
He init    std after 10 layers: 0.63

المثال ٣: Early stopping

Sample output (press Run to produce your own):
stopped after 42 epochs
best validation score: 0.978

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

اختبار قصير

اختبر فهمك

1. At test time dropout is:

2. Why divide by (1 - p) in inverted dropout?

3. What is wrong with initializing all weights to zero?

4. Early stopping stops training when:

5. He initialization scales weights by:

تمارين برمجة

جرّب بإيدك

التمرين 1

اعمل dropout بـ p = 0.3 على h = [1, 2, 3, 4, 5, 6] (rng seed 1) مع إعادة التحجيم، واطبع الناتج.

Apply dropout with p = 0.3 to h = [1, 2, 3, 4, 5, 6] (rng seed 1) with rescaling. Print the result.

(output appears here)

التمرين 2

درّب MLP على load_wine بـ early_stopping=True واطبع عدد الـ epochs.

Train an MLP on load_wine with early_stopping=True and print the number of epochs.

(output appears here)

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

شبكة بـ dropout يدوي على الأرقام

الداتا: Optical Recognition of Handwritten Digits: 1797 images of 8x8 pixels. Source: UCI Machine Learning Repository.

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

الخطوات

  1. حمّل digits، اقسم ٨٠/٢٠، واقسم الـ pixels على 16.
  2. خد الـ MLP من المحاضرة اللي فاتت (64-64-10 بـ ReLU).
  3. في الـ forward وقت التدريب اعمل dropout على الـ hidden بـ p = 0.3 مع إعادة التحجيم.
  4. اطبع دقة الـ test من غير dropout.
Expected output (press Run to produce your own):
test accuracy: 0.972

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

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

ملف 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, Dropout and Numerical Stability and Initialization.