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

الفصل 1 (الجزء 2): Introduction to Deep Learning

Derivatives, the chain rule and automatic differentiation

نبدأ على طول: إزاي نحسب ميل الخطأ، وإزاي الكمبيوتر بيحسبه لوحده.

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

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

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

رسوم متحركة

الـ forward ثم الـ backward والـ chain rule
أثر الـ learning rate

أمثلة Python

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

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

المثال ١: المشتقة بالتقريب

Sample output (press Run to produce your own):
estimated slope at 2: 7.0
exact slope 2x+3 : 7.0

المثال ٢: الـ chain rule بإيدينا

Sample output (press Run to produce your own):
dL/dw by chain rule: -0.1872
dL/dw by nudging   : -0.1872

المثال ٣: loop التدريب (forward, backward, update)

Sample output (press Run to produce your own):
step 0 loss 0.0624
step 1 loss 0.0298
step 2 loss 0.0196
step 3 loss 0.0146
step 4 loss 0.0117

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

اختبار قصير

اختبر فهمك

1. What does a derivative tell us about the loss?

2. The chain rule says the derivative of a chain of functions is:

3. Backpropagation gives the derivative for:

4. The update rule is:

5. Estimating gradients by nudging each parameter is mostly used for:

تمارين برمجة

جرّب بإيدك

التمرين 1

قدّر ميل الدالة f(x) = x^3 عند x = 2 بالتقريب، وقارنه بالقيمة الدقيقة 3x^2.

Estimate the slope of f(x) = x^3 at x = 2 by nudging, then compare with the exact 3x^2.

(output appears here)

التمرين 2

درّب parameter واحد w ليخلّي w * 3 يساوي 6 (loss = (w*3 - 6)^2) بـ 20 خطوة و lr = 0.05، واطبع w.

Train one parameter w so that w * 3 equals 6 (loss = (w*3 - 6)^2): 20 steps, lr = 0.05. Print w.

(output appears here)

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

الـ Linear Regression كـ neuron واحد بالـ gradient

الداتا: Diabetes dataset: 442 patients, target = disease progression one year later. Source: Efron et al., 2004.

License / source: Ships with scikit-learn. Dataset page

الخطوات

  1. خد feature الـ bmi وعمل له standardization.
  2. حدّد w و b بصفر.
  3. في loop من ٣٠٠ خطوة احسب الـ prediction والـ gradient بـ chain rule وحدّث w و b (lr = 0.1).
  4. اطبع w و b وقارنهم بـ np.polyfit على نفس البيانات.
Expected output (press Run to produce your own):
w = 45.2  b = 152.1
polyfit: [ 45.2 152.1]

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

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

ملف 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, Preliminaries: Automatic Differentiation.