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

الفصل 3 (الجزء 1): Multilayer Perceptrons

Hidden layers and activation functions

على طول: ليه الـ layer الخطية مش كفاية، وإيه اللي بتضيفه الطبقة المخفية.

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

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

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

رسوم متحركة

الإشارة بتمشي layer ورا layer

أمثلة Python

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

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

المثال ١: دوال التفعيل

Sample output (press Run to produce your own):
relu   : [0. 0. 2.]
sigmoid: [0.12 0.5  0.88]
tanh   : [-0.96  0.    0.96]

المثال ٢: الـ forward pass لـ MLP

Sample output (press Run to produce your own):
hidden shape: (5, 8)  output shape: (5, 3)

المثال ٣: الخطي يفشل والـ MLP ينجح على circles

Sample output (press Run to produce your own):
linear: 0.5
MLP   : 1.0

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

اختبار قصير

اختبر فهمك

1. Why can't two linear layers in a row beat one?

2. ReLU(x) equals:

3. What does the hidden layer give the network?

4. If X has shape (10, 4) and W1 has shape (4, 8), X @ W1 has shape:

5. More hidden units usually mean:

تمارين برمجة

جرّب بإيدك

التمرين 1

طبّق ReLU على المصفوفة [-3, -1, 0, 2, 5] واطبع النتيجة.

Apply ReLU to [-3, -1, 0, 2, 5] and print it.

(output appears here)

التمرين 2

ابني forward pass لشبكة (3 مدخلات، 5 hidden، 2 خرج) على X بحجم (4, 3) واطبع shape الخرج.

Build the forward pass of a (3 inputs, 5 hidden, 2 outputs) network on X of shape (4, 3). Print the output shape.

(output appears here)

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

MLP يفصل نمط مش خطي (circles)

الداتا: Two Circles (synthetic, generated by sklearn.datasets.make_circles): 400 points, 2 classes, noise 0.15.

License / source: Generated by scikit-learn, no download. Dataset page

الخطوات

  1. ولّد الداتا بـ make_circles وقسّمها ٧٥/٢٥.
  2. درّب LogisticRegression واطبع دقة الـ test.
  3. درّب MLPClassifier بـ hidden (4,) ثم (16,) ثم (16, 16) واطبع دقة كل واحد.
  4. لاحظ الفرق بين الخطي والـ MLP.
Expected output (press Run to produce your own):
linear      : 0.36
MLP (4,)     : 0.99
MLP (16,)    : 1.0
MLP (16, 16) : 0.99

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, Multilayer Perceptrons.