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

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

Sequences and the hidden state

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

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

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

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

رسوم متحركة

الـ RNN متفرّدة عبر الزمن

أمثلة Python

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

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

المثال ١: خطوة RNN واحدة

Sample output (press Run to produce your own):
[ 0.572  0.197 -0.149]

المثال ٢: قراءة تسلسل كامل

Sample output (press Run to produce your own):
0.491
0.541
0.609
0.64
0.555

المثال ٣: الـ gradient بيتلاشى

Sample output (press Run to produce your own):
scale 0.5 step 1 size 1.1256
scale 0.5 step 5 size 0.0235
scale 0.5 step 10 size 0.0007
scale 0.5 step 20 size 0.0
scale 1.5 step 1 size 3.7473
scale 1.5 step 5 size 9.1206
scale 1.5 step 10 size 50.1197
scale 1.5 step 20 size 4367.8465

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

اختبار قصير

اختبر فهمك

1. What does the hidden state hold?

2. Are the weights the same at every time step?

3. BPTT stands for:

4. Why does a plain RNN forget old inputs?

5. What helps with exploding gradients?

تمارين برمجة

جرّب بإيدك

التمرين 1

طبّق خطوة RNN: x = 1، h = 0.5، Wx = 0.8، Wh = 0.4 (أرقام عادية) واطبع tanh(x*Wx + h*Wh).

Apply one RNN step with scalars: x = 1, h = 0.5, Wx = 0.8, Wh = 0.4. Print tanh(x*Wx + h*Wh).

(output appears here)

التمرين 2

كرّر الخطوة دي على الـ input [1, 0, 0] وابدأ بـ h = 0 واطبع الـ h بعد كل خطوة.

Repeat that step over the inputs [1, 0, 0], starting from h = 0. Print h after each step.

(output appears here)

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

قراءة الأرقام صف صف بـ RNN

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

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

الخطوات

  1. حمّل digits واقسم ٨٠/٢٠. كل صورة ٨×٨ بنعتبرها ٨ خطوات، كل خطوة صف من ٨ أرقام.
  2. اعمل RNN بأوزان عشوائية ثابتة (hidden = 64) واقرا الصفوف بالترتيب.
  3. درّب LogisticRegression على آخر hidden state بس.
  4. قارن بمتوسط الصفوف (من غير ترتيب). المتوقع: RNN حوالي 0.875 ومتوسط الصفوف حوالي 0.48، يعني الترتيب فارق.
Expected output (press Run to produce your own):
RNN last state     : 0.875
mean of rows (no order): 0.481

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, Recurrent Neural Networks.