فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة Python
أمثلة قصيرة وبسيطة
الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.
المثال ١: الـ softmax
Sample output (press Run to produce your own): probabilities: [0.659 0.242 0.099] sum: 1.0
المثال ٢: الـ cross-entropy
Sample output (press Run to produce your own): loss when right: 0.105 loss when wrong: 2.996
المثال ٣: تدريب softmax على iris
Sample output (press Run to produce your own): accuracy: 0.973
اختبار قصير
اختبر فهمك
1. What does softmax guarantee about its outputs?
2. Cross-entropy is large when:
3. With 10 classes and 64 features, the weight matrix W has shape:
4. The gradient of cross-entropy with softmax (before averaging) is:
5. A single softmax layer can separate classes with:
تمارين برمجة
جرّب بإيدك
التمرين 1
اكتب softmax واحسبه على z = [1, 2, 3] واطبع الناتج مقرّب لـ 3 أرقام.
Write softmax and apply it to z = [1, 2, 3]. Print the result rounded to 3 digits.
(output appears here)
import numpy as np z = np.array([1.0, 2.0, 3.0]) e = np.exp(z - z.max()) print(np.round(e / e.sum(), 3))
Output
[0.09 0.245 0.665]
التمرين 2
احسب الـ cross-entropy لو الاحتمالات [0.7, 0.2, 0.1] والفئة الصح رقم 1.
Compute the cross-entropy when the probabilities are [0.7, 0.2, 0.1] and the true class is 1.
(output appears here)
import numpy as np p = np.array([0.7, 0.2, 0.1]) true = 1 print(round(float(-np.log(p[true])), 3))
Output
1.609
مشروع صغير في آخر المحاضرة
صنّف الأرقام المكتوبة بخط اليد بـ softmax من الصفر
الداتا: Optical Recognition of Handwritten Digits: 1797 images of 8x8 pixels, 10 classes. Source: UCI Machine Learning Repository.
License / source: Ships with scikit-learn. Dataset page
الخطوات
- حمّل digits، اقسم ٨٠/٢٠ (random_state=0) واقسم الـ pixels على 16.
- اعمل W بحجم (64, 10) و b بأصفار.
- درّب ٢٠٠ خطوة بـ lr = 0.5 على الـ cross-entropy (كل الداتا في كل خطوة).
- اطبع دقة الـ test.
Expected output (press Run to produce your own): test accuracy: 0.944
مشروع نهاية الفصل
ملف المشروع العملي للفصل 2
ملف 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, Linear Neural Networks for Classification.