Blame

6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
1
# 12. Réseaux récurrents
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
2
3
Les réseaux à propagation avant et les réseaux convolutifs transforment une entrée de taille fixe en une sortie en une seule passe, mais de nombreux problèmes se présentent sous forme de séquences dont la longueur varie et dont l'ordre importe (texte, audio, séries temporelles). Un réseau de neurones récurrent (RNN) traite une séquence pas à pas et propage un état caché vers l'avant, de sorte que les entrées passées influencent la sortie courante. Ce module introduit la récurrence, la cellule RNN de base, la façon dont elle est entraînée par rétropropagation à travers le temps, et pourquoi les gradients à longue portée ont tendance à s'évanouir ou à exploser.
4
5
**Objectifs**
6
- Expliquer pourquoi les données séquentielles ont besoin de mémoire et de partage de poids entre les pas de temps.
7
- Écrire la récurrence du RNN de base pour l'état caché et la sortie.
8
- Dérouler une cellule récurrente dans le temps et en lire les paramètres partagés.
9
- Dériver comment la rétropropagation à travers le temps (BPTT) accumule le gradient sur tous les pas.
10
- Diagnostiquer l'évanouissement et l'explosion des gradients à partir du produit des jacobiennes au fil du temps.
11
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
12
## 12.1 Données séquentielles et mémoire
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
13
14
Une séquence est une liste ordonnée d'entrées $x_1, x_2, \dots, x_T$, où $T$ peut différer d'un exemple à l'autre. Un réseau à propagation avant du type vu dans les leçons précédentes attend un unique vecteur de taille fixe $a^{[0]} = x$, de sorte qu'il n'a aucun moyen naturel de consommer une entrée de longueur variable ni de se souvenir de ce qui précédait l'élément courant.
15
16
Deux idées corrigent cela. Premièrement, le réseau conserve un **état caché** (ou mémoire) $h_t$ qui résume tout ce qui est pertinent jusqu'au pas $t$. Deuxièmement, le réseau **partage** un unique jeu de paramètres à chaque pas, de sorte que la même transformation s'applique que la séquence ait 5 éléments ou 500. Le partage garde le nombre de paramètres indépendant de $T$ et permet à un motif appris à une position de généraliser à n'importe quelle autre.
17
18
*Remarque :* le partage de poids dans le temps est l'analogue séquentiel du partage de poids dans l'espace dans un réseau convolutif. Tous deux encodent l'a priori qu'une même caractéristique peut apparaître n'importe où.
19
20
| Configuration | Entrée | Sortie | Exemple |
21
| --- | --- | --- | --- |
22
| Plusieurs vers un | séquence | vecteur unique | sentiment d'une phrase |
23
| Plusieurs vers plusieurs (aligné) | séquence | séquence, même longueur | étiquetage morphosyntaxique |
24
| Plusieurs vers plusieurs (seq2seq) | séquence | séquence, autre longueur | traduction automatique |
25
| Un vers plusieurs | vecteur unique | séquence | légendage d'image |
26
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
27
## 12.2 La cellule RNN de base
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
28
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
29
### 12.2.1 Récurrence
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
30
31
Au pas $t$ la cellule lit l'entrée courante $x_t$ et l'état caché précédent $h_{t-1}$, puis produit un nouvel état caché via une activation $g$ (habituellement $\tanh$) :
32
33
$$\boxed{ h_t = g\left(W_{hh}\, h_{t-1} + W_{xh}\, x_t + b_h\right) }$$
34
35
L'état caché est initialisé à $h_0 = \mathbf{0}$ (ou à un vecteur appris). La sortie par pas est une lecture linéaire de l'état caché :
36
37
$$\boxed{ \hat{y}_t = W_{hy}\, h_t + b_y }$$
38
39
Ici $W_{hh}$ transforme l'état en état, $W_{xh}$ transforme l'entrée en état, et $W_{hy}$ transforme l'état en sortie. Si la taille cachée est $n_h$ et la taille d'entrée est $n_x$, alors $W_{hh}$ est de taille $(n_h \times n_h)$, $W_{xh}$ est de taille $(n_h \times n_x)$, et $b_h$ a pour forme $n_h$.
40
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
41
*Remarque :* cela conserve la convention de biais explicite de tout le cours de Deep Learning. Le biais $b_h$ est un terme additif séparé, jamais incorporé dans les matrices de poids comme le cours de Machine Learning incorporait l'ordonnée à l'origine dans $w^T x$ avec $x_0 = 1$.
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
42
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
43
### 12.2.2 Poids partagés
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
44
45
Le point crucial est que $W_{hh}$, $W_{xh}$, $W_{hy}$, $b_h$ et $b_y$ ne dépendent **pas** de $t$. Les cinq mêmes paramètres sont réutilisés à chaque pas :
46
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
47
$$\boxed{ w = \{W_{hh},\, W_{xh},\, W_{hy},\, b_h,\, b_y\} \quad \text{utilisés à chaque pas } t }$$
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
48
49
Un RNN n'est donc pas un réseau très profond avec des couches distinctes, c'est une petite cellule appliquée de façon répétée, réinjectant sa propre sortie en entrée.
50
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
51
## 12.3 Déroulement dans le temps
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
52
53
Comme la même cellule est réutilisée, on peut **dérouler** la récurrence en une chaîne : on dessine une copie de la cellule par pas de temps et on connecte l'état caché de chaque copie à la suivante. La vue déroulée est un graphe à propagation avant ordinaire (à poids liés), ce qui est exactement ce qui rend possible le calcul du gradient.
54
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
55
![RNN déroulé sur trois pas de temps](/fr/Deep%20Learning/12%20Recurrent%20networks/a/rnn-unrolled.svg)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
56
57
*Déroulé dans le temps, un réseau récurrent réutilise les mêmes poids à chaque pas et propage l'état caché vers l'avant.*
58
59
*Remarque :* les flèches horizontales entre états cachés sont le seul chemin par lequel l'information du passé atteint le présent. Chacune d'elles multiplie par la même matrice $W_{hh}$, ce qui est à la fois la source de la puissance du modèle et de sa difficulté d'entraînement.
60
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
61
## 12.4 Rétropropagation à travers le temps
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
62
63
L'entraînement minimise un coût total qui somme la perte par pas sur la séquence. Avec une perte par pas $L_t$ comparant $\hat{y}_t$ à la cible $y_t$, le coût pour une séquence est :
64
65
$$\boxed{ J = \sum_{t=1}^{T} L_t\left(\hat{y}_t, y_t\right) }$$
66
67
La rétropropagation à travers le temps (BPTT) est une rétropropagation ordinaire exécutée sur le graphe déroulé. Comme $W_{hh}$ est réutilisée à chaque pas, son gradient est la **somme** des contributions de tous les pas :
68
69
$$\boxed{ \frac{\partial J}{\partial W_{hh}} = \sum_{t=1}^{T} \frac{\partial L_t}{\partial W_{hh}} }$$
70
71
Pour un pas unique $t$, la perte dépend de $W_{hh}$ à la fois directement (via $h_t$) et indirectement via chaque état caché antérieur $h_k$ avec $k \le t$, puisque chacun d'eux a lui-même été produit avec $W_{hh}$. En appliquant la règle de dérivation en chaîne à travers la chaîne d'états, on obtient :
72
73
$$\boxed{ \frac{\partial L_t}{\partial W_{hh}} = \sum_{k=1}^{t} \frac{\partial L_t}{\partial h_t}\left(\prod_{i=k+1}^{t} \frac{\partial h_i}{\partial h_{i-1}}\right)\frac{\partial h_k}{\partial W_{hh}} }$$
74
75
*Remarque :* en pratique la somme sur $k$ est tronquée après une fenêtre fixe, ce qu'on appelle la BPTT tronquée. Elle borne la mémoire et le calcul par mise à jour au prix d'ignorer les dépendances plus longues que la fenêtre.
76
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
77
## 12.5 Évanouissement et explosion des gradients
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
78
79
Le produit interne $\prod_{i=k+1}^{t} \frac{\partial h_i}{\partial h_{i-1}}$ est ce qui transporte l'information de gradient du pas $t$ jusqu'au pas $k$. À partir de la récurrence $h_i = g(W_{hh} h_{i-1} + W_{xh} x_i + b_h)$, chaque facteur vaut :
80
81
$$\boxed{ \frac{\partial h_i}{\partial h_{i-1}} = \operatorname{diag}\!\left(g'(z_i)\right) W_{hh} }$$
82
83
où $z_i = W_{hh} h_{i-1} + W_{xh} x_i + b_h$ est la pré-activation au pas $i$. En composant sur tout l'écart de $k$ à $t$, on obtient un produit de $t - k$ matrices de ce type :
84
85
$$\boxed{ \prod_{i=k+1}^{t} \frac{\partial h_i}{\partial h_{i-1}} = \prod_{i=k+1}^{t} \operatorname{diag}\!\left(g'(z_i)\right) W_{hh} }$$
86
87
Ce produit de $t - k$ facteurs quasi identiques se comporte à peu près comme une matrice élevée à la puissance $t - k$. Si la magnitude pertinente (informellement, la plus grande valeur singulière de $\operatorname{diag}(g'(z_i)) W_{hh}$) est inférieure à $1$, le produit rétrécit géométriquement vers zéro à mesure que l'écart grandit, de sorte que les gradients lointains **s'évanouissent**. Si elle est supérieure à $1$, le produit explose et les gradients **explosent**.
88
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
89
![Magnitude du gradient en fonction du décalage temporel sur une échelle logarithmique](/fr/Deep%20Learning/12%20Recurrent%20networks/a/bptt-decay.png)
36084c lugonthier 2026-07-02 14:39:19
Add new content and images for Linear Models, Regularization, SVMs, and Decision Trees - Added images for linear regression, logistic regression, and perceptron. - Introduced a new section on Regularization and High-Dimensional Inference with detailed explanations and images. - Added content on Support Vector Machines, including definitions, loss functions, and kernel methods. - Created a new section on Decision Trees and Ensemble Methods, covering CART, bagging, random forests, and boosting. - Included relevant images to illustrate concepts in Decision Trees and Ensemble Methods.
90
91
*Au fil de nombreux pas de temps, le gradient rétrécit ou croît géométriquement, de sorte que les dépendances à longue portée sont difficiles à apprendre pour un RNN simple.*
92
93
| Régime | Produit dans le temps | Effet sur l'entraînement |
94
| --- | --- | --- |
95
| Magnitude du facteur $< 1$ | décroît vers $0$ | les gradients à longue portée s'évanouissent, aucune mémoire longue apprise |
96
| Magnitude du facteur $\approx 1$ | reste bornée | stable, le cas idéal |
97
| Magnitude du facteur $> 1$ | croît sans borne | les gradients explosent, les mises à jour divergent |
98
99
*Remarque :* les gradients qui explosent sont habituellement maîtrisés par **écrêtage du gradient** (rééchelonner le gradient quand sa norme dépasse un seuil). Les gradients qui s'évanouissent sont plus difficiles à traiter, car le signal est perdu plutôt que simplement grand, et aucun rééchelonnement simple ne le récupère.
100
101
Comme une activation saturante telle que $\tanh$ a $g' \le 1$ partout, le facteur diagonal tend à tirer le produit vers l'évanouissement, ce qui rend difficile pour un RNN de base l'apprentissage de dépendances distantes de plus de quelques dizaines de pas. Cette limitation est précisément ce qui motive les cellules à portes, qui ajoutent un chemin quasi linéaire le long duquel l'état peut circuler sans écrasement répété.
102
103
*La prochaine leçon introduit le LSTM et le GRU, des architectures à portes qui transportent un état de cellule à travers des mises à jour additives afin que les gradients puissent traverser de longues portées sans s'évanouir.*
104
105
---
6b31d5 lugonthier 2026-07-15 12:37:13
feat: Update "Decision trees and ensemble methods" module with new content and visuals - Revamped the introduction to ensemble methods, emphasizing the benefits of combining models. - Expanded sections on decision trees, bagging, and boosting, including detailed explanations and formulas. - Added new SVG diagrams illustrating the bagging process, the transition from stumps to trees, and variance reduction. - Introduced new images for AdaBoost rounds and variance reduction to enhance understanding.
106
Suivant : [LSTM et GRU](/fr/Deep%20Learning/13%20LSTM%20and%20GRU) · [Vue d'ensemble du cours](/fr/Deep%20Learning)