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

الفصل 2 (الجزء 2): Linear Neural Networks

Softmax regression and cross-entropy

على طول: إزاي الشبكة تختار بين أكتر من فئة بالـ softmax.

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

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

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

رسوم متحركة

الـ softmax بيحوّل الـ scores لاحتمالات

أمثلة 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

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

اختبار قصير

اختبر فهمك

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)

التمرين 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)

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

صنّف الأرقام المكتوبة بخط اليد بـ 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

الخطوات

  1. حمّل digits، اقسم ٨٠/٢٠ (random_state=0) واقسم الـ pixels على 16.
  2. اعمل W بحجم (64, 10) و b بأصفار.
  3. درّب ٢٠٠ خطوة بـ lr = 0.5 على الـ cross-entropy (كل الداتا في كل خطوة).
  4. اطبع دقة الـ test.
Expected output (press Run to produce your own):
test accuracy: 0.944

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

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

ملف 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, Linear Neural Networks for Classification.