PhD

The LaTeX sources of my Ph.D. thesis
git clone https://esimon.eu/repos/PhD.git
Log | Files | Refs | README | LICENSE

lstm.tex (3094B)


      1 \begin{tikzpicture}[
      2 		inval/.style={shape=circle,draw=black,inner sep=0,minimum size=16},
      3 		mult/.style={shape=circle,draw=black,inner sep=0,minimum size=6,path picture={
      4 			\draw[black,thick,line cap=round] (45:0.075) -- (225:0.075) (135:0.075) -- (315:0.075);
      5 		}},
      6 		sigm/.style={shape=circle,draw=black,inner sep=0,minimum size=16,path picture={
      7 			\draw[step=0.05,very thin,color=gray!20] (-1,-1) grid (1,1);
      8 			\draw[color=gray!80] (-1,-0.075) -- (1,-0.075) (0,-1) -- (0,1);
      9 			\draw[thick] (-1, -0.075) -- (-0.15,-0.075) edge[thick,out=360,in=180,looseness = 1] (0.15,0.15) (0.15,0.15) -- (1, 0.15);
     10 		}},
     11 		tanh/.style={shape=circle,draw=black,inner sep=0,minimum size=16,path picture={
     12 			\draw[step=0.05,very thin,color=gray!20] (-1,-1) grid (1,1);
     13 			\draw[color=gray!80] (-1,0) -- (1,0) (0,-1) -- (0,1);
     14 			\draw[thick] (-1, -0.15) -- (-0.15,-0.15) edge[out=360,in=180,looseness=1] (0.15,0.15) (0.15,0.15) -- (1, 0.15);
     15 		}},
     16 		tanhd/.style={shape=circle,draw=black,inner sep=0,minimum size=16,path picture={
     17 			\draw[step=0.05,very thin,color=gray!4] (-1,-1) grid (1,1);
     18 			\draw[color=gray!16] (-1,0) -- (1,0) (0,-1) -- (0,1);
     19 			\draw[thick] (-1, -0.15) -- (-0.15,-0.15) edge[out=360,in=180,looseness=1] (0.15,0.15) (0.15,0.15) -- (1, 0.15);
     20 		}},
     21 	]
     22 	\node (x) at (-4.2, 0) {\(\vctr{x}_t, \vctr{h}_{t-1}\)};
     23 	\node (h) at (3.5, 0) {\(\vctr{h}_t\)};
     24 
     25 	\node[inval,very thick] (c) at (0, 0) {\(\vctr{c}_t\)};
     26 	\node[sigm] (i) at (-1.25, 1.5) {};
     27 	\node[sigm] (o) at (2.5, 1.5) {};
     28 	\node[sigm] (f) at (0, -1.5) {};
     29 
     30 	\node[mult] (i_mult) at (-1.25, 0) {};
     31 	\node[mult] (o_mult) at (2.5, 0) {};
     32 	\node[mult] (f_mult) at (0, -0.75) {};
     33 
     34 	\node[tanh] (i_act) at (-2.5, 0) {};
     35 	\node[tanh] (c_act) at (1.25, 0) {};
     36 
     37 	\node[above] at (c.north) {\tiny Cell};
     38 	\node[left,xshift=1mm] at (i.west) {\tiny Input Gate};
     39 	\node[left] at (o.west) {\tiny Output Gate};
     40 	\node[left] at (f.west) {\tiny Forget Gate};
     41 
     42 	\draw
     43 		let \p1 = (o.north) in
     44 		let \p2 = (o.east) in
     45 		let \p3 = (f.south) in
     46 		let \p4 = (i_act.west) in
     47 		(\x4, \y3) rectangle (\x2, \y1);
     48 
     49 	\draw[arrow] (x) -- (i_act);
     50 	\draw (-3.5,0) .. controls ++(0:1) and ++(0:-1) .. (-2.5, 2.2);
     51 	\draw (-3.5,0) .. controls ++(0:1) and ++(0:-1) .. (-2.5, -2.2);
     52 
     53 	\draw (-2.5,-2.2) -- (-0.3,-2.2);
     54 	\draw[arrow] (-0.3,-2.2) to[out=0,in=-90] (f);
     55 
     56 	\draw (-2.5,2.2) -- (2.2,2.2);
     57 	\draw[arrow] (-1.55,2.2) to[out=0,in=90] (i);
     58 	\draw[arrow] (2.2,2.2) to[out=0,in=90] (o);
     59 
     60 	\draw[arrow] (o_mult) -- (h);
     61 
     62 	\draw[arrow] (i_act) -- (i_mult);
     63 	\draw[arrow] (i) -- (i_mult) node[pos=0.4,left=-0.1] {\(\vctr{i}_t\)};
     64 	\draw[arrow] (i_mult) -- (c);
     65 	\draw[arrow] (c) -- (i);
     66 	\draw[arrow] (c) -- (o);
     67 	\draw[arrow] (c) -- (c_act);
     68 	\draw[arrow] (c_act) -- (o_mult);
     69 	\draw[arrow] (o) -- (o_mult) node[pos=0.4,left=-0.1] {\(\vctr{o}_t\)};
     70 	\draw[arrow] (f) -- (f_mult) node[pos=0.4,right=-0.05] {\(\vctr{f}_t\)};
     71 
     72 	\draw (c) edge [arrow, out=300, in=50] (f_mult.north east);
     73 	\draw (f_mult.north west) edge [arrow, out=130, in=250] (c);
     74 
     75 	\node at (1.8,-1.25) {\LARGE LSTM};
     76 
     77 	\draw (c) edge [arrow, out=210, in=150] (f);
     78 \end{tikzpicture}%