فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة 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
اختبار قصير
اختبر فهمك
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)
import numpy as np rng = np.random.default_rng(1) h = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]) p = 0.3 mask = rng.random(6) > p print(np.round(h * mask / (1 - p), 2))
Output
[1.43 2.86 0. 5.71 7.14 8.57]
التمرين 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)
from sklearn.datasets import load_wine from sklearn.preprocessing import StandardScaler from sklearn.neural_network import MLPClassifier X, y = load_wine(return_X_y=True) X = StandardScaler().fit_transform(X) m = MLPClassifier((32,), early_stopping=True, max_iter=1000, random_state=0).fit(X, y) print(m.n_iter_)
Output
35
مشروع صغير في آخر المحاضرة
شبكة بـ dropout يدوي على الأرقام
الداتا: Optical Recognition of Handwritten Digits: 1797 images of 8x8 pixels. Source: UCI Machine Learning Repository.
License / source: Ships with scikit-learn. Dataset page
الخطوات
- حمّل digits، اقسم ٨٠/٢٠، واقسم الـ pixels على 16.
- خد الـ MLP من المحاضرة اللي فاتت (64-64-10 بـ ReLU).
- في الـ forward وقت التدريب اعمل dropout على الـ hidden بـ p = 0.3 مع إعادة التحجيم.
- اطبع دقة الـ test من غير dropout.
Expected output (press Run to produce your own): test accuracy: 0.972
مشروع نهاية الفصل
ملف المشروع العملي للفصل 4
ملف 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.