pcnn.tex (3909B)
1 \begin{tikzpicture}[ 2 word/.style={text depth=0,anchor=center,inner sep=0}, 3 flow/.style={thin,-latex,color=black!80}, 4 square/.style={regular polygon,regular polygon sides=4, inner sep=0}, 5 sidebrace/.style={decorate,decoration={brace,amplitude=0.3em,mirror}}, 6 sidenote/.style={left,midway,xshift=-0.4em,text depth=0}, 7 transform/.style={rotate=-90,draw,align=center,scale=0.7,rounded corners=0.1cm}] 8 \makeatletter 9 \ifthesis@presentation 10 \def\positionalSize{\tiny} 11 \else 12 \def\positionalSize{\scriptsize} 13 \fi 14 \makeatother 15 \foreach \i/\da/\db/\name/\text in { 0/-2/-8/x00/Founded, 16 1/-1/-7/x01/in, 17 2/ / /e1/\strong{Rome}, 18 3/ 1/-5/x10/{(}, 19 4/ 2/-4/x11/then, 20 5/ 3/-3/x12/capital, 21 6/ 4/-2/x13/of, 22 7/ 5/-1/x14/the, 23 8/ / /e2/\strong{Papal States}, 24 9/ 7/ 1/x20/{)}, 25 10/ 8/ 2/x21/in, 26 11/ 9/ 3/x22/1575, 27 12/10/ 4/x23/by, 28 13/11/ 5/x24/St, 29 14/12/ 6/x25/Philip, 30 15/13/ 7/x26/\ldots}{ 31 \node[word] (t\name) at (-0.3, -0.3*\i+0.4*0.3) {\footnotesize \text}; 32 \node at (2.4, -0.3*\i+0.15) {\positionalSize \(\da\)}; 33 \node at (2.8, -0.3*\i+0.15) {\positionalSize \(\db\)}; 34 \node[draw,minimum width=20mm,minimum height=0.3cm,anchor=north west] (\name) at (1, -0.3*\i+0.3) {}; 35 } 36 37 \draw (2.6, 0.3) -- (2.6, -4.5); 38 \draw (2.2, 0.3) -- (2.2, -4.5); 39 40 \draw[flow] (x00.east) -- (4, -0.55); 41 \draw[flow] (x01.east) -- (4, -0.65); 42 \draw[flow] (x10.east) -- (4, -1.95); 43 \draw[flow] (x11.east) -- (4, -2.05); 44 \draw[flow] (x12.east) -- (4, -2.15); 45 \draw[flow] (x13.east) -- (4, -2.25); 46 \draw[flow] (x14.east) -- (4, -2.35); 47 \draw[flow] (x20.east) -- (4, -3.3); 48 \draw[flow] (x21.east) -- (4, -3.4); 49 \draw[flow] (x22.east) -- (4, -3.5); 50 \draw[flow] (x23.east) -- (4, -3.6); 51 \draw[flow] (x24.east) -- (4, -3.7); 52 \draw[flow] (x25.east) -- (4, -3.8); 53 \draw[flow] (x26.east) -- (4, -3.9); 54 55 \draw[pattern=north east lines,pattern color=Dark2-C,draw=none] (e1.north west) rectangle (e1.south east); 56 \draw[pattern=north east lines,pattern color=Dark2-C,draw=none] (e2.north west) rectangle (e2.south east); 57 58 \draw [sidebrace] (tx00.north -| -1.4,0) -- (tx01.south -| -1.4,0) node [sidenote] {prefix}; 59 \draw [sidebrace] (tx10.north -| -1.4,0) -- (tx14.south -| -1.4,0) node [sidenote] {infix}; 60 \draw [sidebrace] (tx20.north -| -1.4,0) -- (tx26.south -| -1.4,0) node [sidenote] {suffix}; 61 62 \node[draw,square,fill=black!20,rounded corners=0.1cm] (linear) at (8, -2) {Linear}; 63 \node[transform,minimum width=1.4cm/0.7,anchor=north] (softmax) at (9.3, -2) {softmax}; 64 65 \node[right=2mm of softmax.north] {\(P(\rndm{r}\mid s)\)}; 66 67 \draw [sidebrace] (2.25, -4.6) -- (3, -4.6) node [below,midway,yshift=-1mm,xshift=-3mm,align=left,text width=4cm,anchor=north west] {positional\\embeddings}; 68 \draw [sidebrace] (1, -4.6) -- (2.15, -4.6) node [below,midway,yshift=-1mm,xshift=3mm,align=right,text width=4cm,anchor=north east] {\hfill word\\\hfill embeddings}; 69 70 \foreach \i/\n in {-1/p,-2.5/i,-4/s}{ 71 \foreach \j/\c in {0.3/20,0.2/40,0.1/20,0/40}{ 72 \filldraw[fill=black!\c,fill opacity=0.7,rounded corners=0.05cm] (4+\j, \i+\j) rectangle +(0.8, 0.8); 73 } 74 \node at (4+0.4, \i+0.4) {\footnotesize Conv}; 75 76 \node[transform,minimum width=1.1cm/0.7,anchor=north east] at (6, \i) {max\\pooling}; 77 \node[transform,minimum width=1.1cm/0.7,anchor=north east] (relu\n) at (6.5, \i) {tanh}; 78 79 \draw[flow] (relu\n) -- (linear); 80 } 81 \end{tikzpicture}