فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة 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
اختبار قصير
اختبر فهمك
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)
import numpy as np z = np.array([-3.0, -1.0, 0.0, 2.0, 5.0]) print(np.maximum(0, z))
Output
[0. 0. 0. 2. 5.]
التمرين 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)
import numpy as np rng = np.random.default_rng(1) X = rng.normal(size=(4, 3)) W1 = rng.normal(size=(3, 5)); W2 = rng.normal(size=(5, 2)) out = np.maximum(0, X @ W1) @ W2 print(out.shape)
Output
(4, 2)
مشروع صغير في آخر المحاضرة
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
الخطوات
- ولّد الداتا بـ make_circles وقسّمها ٧٥/٢٥.
- درّب LogisticRegression واطبع دقة الـ test.
- درّب MLPClassifier بـ hidden (4,) ثم (16,) ثم (16, 16) واطبع دقة كل واحد.
- لاحظ الفرق بين الخطي والـ 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.