فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة 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
اختبار قصير
اختبر فهمك
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)
f = lambda x: x ** 3
h = 1e-5
x = 2.0
print('estimated:', round((f(x + h) - f(x)) / h, 2))
print('exact :', 3 * x ** 2)
Output
estimated: 12.0 exact : 12.0
التمرين 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)
w, lr = 0.0, 0.05
for step in range(20):
w -= lr * 2 * (w * 3 - 6) * 3
print(round(w, 3))
Output
2.0
مشروع صغير في آخر المحاضرة
الـ 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
الخطوات
- خد feature الـ bmi وعمل له standardization.
- حدّد w و b بصفر.
- في loop من ٣٠٠ خطوة احسب الـ prediction والـ gradient بـ chain rule وحدّث w و b (lr = 0.1).
- اطبع 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 فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.
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.