diff --git a/Glossary.tex b/Glossary.tex index 8e6d1dc..cdb6ebd 100644 --- a/Glossary.tex +++ b/Glossary.tex @@ -61,6 +61,9 @@ % {{{ acronyms% \setabbreviationstyle[acronym]{long-short} +\newacronym{GRU}{GRU}{Gated Recurrent Units} +\newacronym{LSTM}{LSTM}{Long-term Short-term Memory} +\newacronym{BPTT}{BPTT}{Backpropagation through time} \newacronym{CNN}{CNN}{Convolutional Neural Network} \newacronym{RNN}{RNN}{Recurrent Neural Network} \newacronym{SSE}{SSE}{Summed Squared Error} diff --git a/chapters/Neural_Networks/RNN.tex b/chapters/Neural_Networks/RNN.tex index 4ee58fa..4c0c564 100644 --- a/chapters/Neural_Networks/RNN.tex +++ b/chapters/Neural_Networks/RNN.tex @@ -1,3 +1,102 @@ \chapter{\texorpdfstring{\glsxtrlongpl{RNN}}{\glsfmtlongpl{CNN}}}% \label{cha:RNNs} +\glspl{RNN} stellen eine Erweiterung von \glspl{CNN} (\cref{cha:CNNs}) dar. +Hierbei wir nicht nur aus einer einmaligen Eingabe eine Ausgabe produziert. +Stattdessen ist die Anzahl der Ein"~ und Ausgabeelemente flexibel gestaltet. +Hierbei ist die Mehrzahl nicht im absoluten Sinne, +sondern im zeitlichen Sinne zu verstehen (mehrere Eingaben\slash\,Ausgaben hintereinander). +\begin{figure}[H] + \centering + \includegraphics[width=0.8\textwidth]{RNN_process_sequences.png} + \caption{Verschiedene Prozess Sequenzen eines \texorpdfstring{\gls{RNN}}{RNN}} + \label{fig:rnn_process_sequences} +\end{figure} +\begin{wrapfigure}{r}{.3\textwidth} + \centering + \includegraphics[width=0.5\linewidth]{vanilla_rnn.png} + \caption{Vanilla \texorpdfstring{\glsxtrshort{RNN}}{\glsfmtshort{RNN}}} + \label{fig:} +\end{wrapfigure} +\glspl{RNN} unterscheiden sich vor allem darin von \glspl{CNN}, +dass sie zu jedem Zeitpunkt einen festen Zustand $h$ haben. +Der Zustand ergibt sich aus der Rekurrenz Gleichung (recurrence formula). +\begin{align} \label{eq:recurrence formula} + &\bm h_t = f_{\bm W}(\bm h_{t-1},\bm x_t) +\end{align} +\begin{itemize} + \item $\bm h_t$: neuer Zustand + \item $f_{\bm W}$: Funktion mit den Parametern $\bm W$ + \item $\bm h_{t-1}$: alter Zustand + \item $\bm x_t$ Input zum Zeitpunkt $t$ +\end{itemize} +\section{\texorpdfstring{\glsxtrshort{RNN}}{\glsfmtshort{RNN}} Computational Graph}% +\label{sec:RNN Computational Graph} +{\color{red} Vorlesung 09 Folien 58-64} + +\section{\texorpdfstring{\glsxtrfull{BPTT}}{\glsfmtfull{BPTT}}}% +\label{sec:BPTT} +Die Gewichte in einem \gls{RNN} können mithilfe von \gls{BPTT} angepasst werden. +Hierbei wird der Gradient wie bei der normalen \nameref{sec:Backpropagation} errechnet, +wobei zusätzlich noch die Differentiation in Zeitrichtung durchgeführt werden muss. +\begin{figure}[H] + \centering + \includegraphics[width=0.8\textwidth]{BPTT.png} + \caption{\texorpdfstring{\glsxtrlong{BPTT}}{\glsfmtlong{BPTT}}} + \label{fig:BPTT} +\end{figure} + +\subsection{Truncated \texorpdfstring{\glsxtrshort{BPTT}}{\glsfmtshort{BPTT}}}% +\label{sub:Truncated BPTT} +Da \gls{BPTT} bei einer langen Zeitfolge sehr rechenintensiv ist, +wird der Algorithmus zumeist nur für die letzten paar Schritte druchgeführt. +\begin{figure}[H] + \centering + \includegraphics[width=0.6\textwidth]{truncated_BPTT.png} + \caption{Truncated \texorpdfstring{\glsxtrshort{BPTT}}{\glsfmtshort{BPTT}}} + \label{fig:truncated_BPTT} +\end{figure} + +\subsection{Gradient Flow}% +\label{sub:Gradient Flow} +\includegraphics[scale=.6]{gradient_flow_vanilla_rnns.png}\\ +\includegraphics[scale=.6]{gradient_flow_vanilla_rnns2.png} + +\section{\texorpdfstring{\glsxtrfull{LSTM}}{\glsfmtfull{LSTM}}}% +\label{sec:LSTM} +Da die Probleme des Gradient Flows bei Vanilla \glspl{RNN} (explodierende oder verschwindende Gradienten) gerade bei langen Zeitfolgen problematisch sind, +wurde das System der \glspl{LSTM} entwickelt. +Hierbei wird zu dem Zustand $\bm h$ noch ein weiterer Speicherzustand $\bm c$ hinzugefügt. +Die Berechnung erfolgt durch +\begin{equation} \label{eq:LSTM function} + \bm c = \bm f_t\circ\bm c_{t-1} + \bm i_t\circ\bm g_t,\quad \bm h_t = \bm o_t\circ\tanh{\bm c_t} +\end{equation} +\begin{wrapfigure}{r}{.4\textwidth} + \centering + \includegraphics[width=\linewidth]{LSTM.png} + \caption{\texorpdfstring{\glsxtrshort{LSTM}}{\glsfmtshort{LSTM}}} + \label{fig:LSTM} +\end{wrapfigure} +\begin{itemize} + \item $\bm c$ Speicherzustand zum Zeitpunkt $t$ bzw. $t-1$ + \item $\bm f$ Forget Gate: \tabto{3cm}$\bm f_t = \nomeq{sigmoid}\left(\bm W_f \begin{bmatrix} \bm h_{t-1} \\ \bm x_t \end{bmatrix}\right)$ + \item $\bm i$ Input Gate: \tabto{3cm}$\bm i_t = \nomeq{sigmoid}\left( \bm W_i \begin{bmatrix} \bm h_{t-1} \\ \bm x_t \end{bmatrix}\right) $ + \item $\bm g$ Gate Gate: \tabto{3cm}$\bm g_t = \tanh \left(\bm W_g \begin{bmatrix} \bm h_{t-1} \\ \bm x_t \end{bmatrix}\right)$ + \item $\bm o$ Output Gate: \tabto{3cm}$\bm o_t = \tanh \left(\bm W_o \begin{bmatrix} \bm h_{t-1} \\ \bm x_t \end{bmatrix}\right)$ +\end{itemize} +Die Gatter sind dafür da, +zu entscheiden, +wann das \gls{RNN} sich ein Zwischenergebnis merkt und wann nicht + +\subsection{Gradient Flow}% +\label{sub:LSTM:Gradient Flow} +\includegraphics[scale=.6]{LSTM_gradient_flow.png}\\ +\includegraphics[scale=.6]{LSTM_gradient_flow2.png} + +\subsection{Deep \texorpdfstring{\glsxtrshortpl{LSTM}}{\glsfmtshortpl{LSTM}}}% +\label{sub:Deep LSTMs} +\includegraphics[scale=.6]{deep_lstms.png} + +\section{\texorpdfstring{\glsxtrfull{GRU}}{\glsfmtfull{GRU}}}% +\label{sec:GRU} +\includegraphics[scale=.6]{GRU.png} diff --git a/images/BPTT.png b/images/BPTT.png new file mode 100644 index 0000000..b44026a Binary files /dev/null and b/images/BPTT.png differ diff --git a/images/GRU.png b/images/GRU.png new file mode 100644 index 0000000..12a5f2e Binary files /dev/null and b/images/GRU.png differ diff --git a/images/LSTM.png b/images/LSTM.png new file mode 100644 index 0000000..3f39bbb Binary files /dev/null and b/images/LSTM.png differ diff --git a/images/LSTM_gradient_flow.png b/images/LSTM_gradient_flow.png new file mode 100644 index 0000000..f672017 Binary files /dev/null and b/images/LSTM_gradient_flow.png differ diff --git a/images/LSTM_gradient_flow2.png b/images/LSTM_gradient_flow2.png new file mode 100644 index 0000000..560a018 Binary files /dev/null and b/images/LSTM_gradient_flow2.png differ diff --git a/images/RNN_process_sequences.png b/images/RNN_process_sequences.png new file mode 100644 index 0000000..53bf50c Binary files /dev/null and b/images/RNN_process_sequences.png differ diff --git a/images/deep_lstms.png b/images/deep_lstms.png new file mode 100644 index 0000000..86dd628 Binary files /dev/null and b/images/deep_lstms.png differ diff --git a/images/gradient_flow_vanilla_rnns.png b/images/gradient_flow_vanilla_rnns.png new file mode 100644 index 0000000..473c6a5 Binary files /dev/null and b/images/gradient_flow_vanilla_rnns.png differ diff --git a/images/gradient_flow_vanilla_rnns2.png b/images/gradient_flow_vanilla_rnns2.png new file mode 100644 index 0000000..51e93db Binary files /dev/null and b/images/gradient_flow_vanilla_rnns2.png differ diff --git a/images/truncated_BPTT.png b/images/truncated_BPTT.png new file mode 100644 index 0000000..348e804 Binary files /dev/null and b/images/truncated_BPTT.png differ diff --git a/images/vanilla_rnn.png b/images/vanilla_rnn.png new file mode 100644 index 0000000..6d0c316 Binary files /dev/null and b/images/vanilla_rnn.png differ