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

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

LSTM, GRU and gates

على طول: البوابات اللي بتخلّي الشبكة تقرر تفتكر إيه وتنسى إيه.

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

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

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

رسوم متحركة

البوابة

أمثلة Python

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

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

المثال ١: بوابة

Sample output (press Run to produce your own):
gate 0.01 -> [ 0.01 -0.01  0.  ]
gate 0.5 -> [ 1.   -0.5   0.25]
gate 0.99 -> [ 1.99 -0.99  0.5 ]

المثال ٢: خطوة GRU

Sample output (press Run to produce your own):
z = 0.05 -> h = [0.24 0.81]
z = 0.5 -> h = [ 0.6  -0.05]
z = 0.95 -> h = [ 0.96 -0.91]

المثال ٣: الـ perplexity

Sample output (press Run to produce your own):
loss 1.325  perplexity 3.76

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

اختبار قصير

اختبر فهمك

1. A gate value near 0 means:

2. In a GRU, z near 1 means:

3. Which part is extra in an LSTM?

4. Why do gates help gradients?

5. Perplexity is:

تمارين برمجة

جرّب بإيدك

التمرين 1

احسب sigmoid(0) واطبع الناتج.

Compute sigmoid(0) and print it.

(output appears here)

التمرين 2

خطوة GRU: z = 0.9، h_old = 1.0، candidate = -1.0. اطبع h.

One GRU step: z = 0.9, h_old = 1.0, candidate = -1.0. Print h.

(output appears here)

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

RNN عادية مقابل RNN بتحتفظ بالقديم (leaky)

الداتا: Optical Recognition of Handwritten Digits: 1797 images of 8x8 pixels. Source: UCI Machine Learning Repository.

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

الخطوات

  1. استخدم نفس الإعداد: صفوف الأرقام كخطوات وأوزان ثابتة.
  2. في النسخة الـ leaky الحالة الجديدة = (1 - leak) × القديمة + leak × الجديدة، وده شبه بوابة update ثابتة.
  3. درّب LogisticRegression على آخر حالة في الحالتين.
  4. قارن. المتوقع: العادية حوالي 0.875 والـ leaky حوالي 0.90. (ملاحظة: البوابة هنا ثابتة مش متعلّمة).
Expected output (press Run to produce your own):
plain RNN : 0.875
leaky RNN : 0.9

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

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

ملف 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, Modern Recurrent Neural Networks.