



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  \begin{tikzpicture}
   
        \setlength{\base}{0.9cm}

        \tikzstyle{rnnnode} = [rounded corners=1pt,minimum size=0.5\base,draw,inner sep=0pt,outer sep=0pt]
        \tikzstyle{wordnode} = [font=\tiny]

        % RNN translation model
        \begin{scope}[local bounding box=RNNMT]
            % RNN Encoder
            \coordinate (eemb0) at (0,0);
            \foreach \x [count=\y from 0] in {1,2,...,4}
                \node[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=west] (eemb\x) at ([xshift=0.4\base]eemb\y.east) {};
            \foreach \x in {1,2,...,4}
                \node[rnnnode,fill=blue!30!white,anchor=south] (enc\x) at ([yshift=0.5\base]eemb\x.north) {};
            \node[wordnode,left=0.4\base of enc1,font=\scriptsize] (init) {0};
 			\node[wordnode,anchor=east] (init2) at ([xshift=-3.0em]init.west){};
               {
                \node[rnnnode,fill=purple] (repr) at (enc4) {};
                \node[wordnode] (label) at ([xshift=3.5em]enc4.east) {源语言句子表示};
                \draw[->,dashed,thick] (label.west) -- (enc4.east);
            }

            \node[wordnode,below=0pt of eemb1,font=\scriptsize] (encwordin1) {我};
            \node[wordnode,below=0pt of eemb2,font=\scriptsize] (encwordin2) {很};
            \node[wordnode,below=0pt of eemb3,font=\scriptsize] (encwordin3) {好};
            \node[wordnode,below=0pt of eemb4,font=\scriptsize] (encwordin4) {$\langle$eos$\rangle$};
%大括号
\draw[decorate,thick,decoration={mirror,brace}]([xshift=0.0em,yshift=-1.5em]eemb1.south west) --([xshift=0.0em,yshift=-1.5em]eemb4.south east) node [font=\scriptsize,xshift=-3.8em,yshift=-1.0em,align=center](label2) {编码器};			


            % RNN Decoder
            \foreach \x in {1,2,...,4}
                 \node[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=south] (demb\x) at ([xshift=0.0em,yshift=3.0em]enc\x.north) {};
            \foreach \x in {1,2,...,4}
                \node[rnnnode,fill=blue!30!white,anchor=south] (dec\x) at ([yshift=0.5\base]demb\x.north) {};
            \foreach \x in {1,2,...,4}
                \node[rnnnode,minimum height=0.5\base,fill=red!30!white,anchor=south] (softmax\x) at ([yshift=0.5\base]dec\x.north) {};

            % Decoder input words
            \node[wordnode,below=0pt of demb1,font=\scriptsize] (decwordin) {$\langle$sos$\rangle$};
            \ExtractX{$(demb2.south)$}
            \ExtractY{$(decwordin.base)$}
            \node[wordnode,anchor=base,font=\scriptsize] () at (\XCoord,\YCoord) {I};
            \ExtractX{$(demb3.south)$}
            \ExtractY{$(decwordin.base)$}
            \node[wordnode,anchor=base,font=\scriptsize] () at (\XCoord,\YCoord) {am};
            \ExtractX{$(demb4.south)$}
            \ExtractY{$(decwordin.base)$}
            \node[wordnode,anchor=base,font=\scriptsize] () at (\XCoord,\YCoord) {fine};
                        


            % Decoder output words
            \node[wordnode,above=0pt of softmax1,font=\scriptsize] (decwordout1) {I};
            \ExtractX{$(softmax2.north)$}
            \ExtractY{$(decwordout1.base)$}
            \node[wordnode,anchor=base,font=\scriptsize] (decwordout2) at (\XCoord,\YCoord) {am};
            \ExtractX{$(softmax3.north)$}
            \ExtractY{$(decwordout1.base)$}
            \node[wordnode,anchor=base,font=\scriptsize] (decwordout3) at (\XCoord,\YCoord) {fine};
                        
            \ExtractX{$(softmax4.north)$}
            \ExtractY{$(decwordout1.base)$}
            \node[wordnode,anchor=base,font=\scriptsize] (decwordout4) at (\XCoord,\YCoord) {$\langle$eos$\rangle$};
			%大括号
\draw[decorate,thick,decoration={brace}]([xshift=0.0em,yshift=1.3em]softmax1.north west) --([xshift=0.0em,yshift=1.3em]softmax4.north east) node [font=\scriptsize,xshift=-3.8em,yshift=1.0em,align=center](label1) {解码器};

            % Connections
            \draw[-latex'] (init.east) to (enc1.west);
            \foreach \x in {1,2,...,4}
                \draw[-latex'] (eemb\x) to (enc\x);
            \foreach \x in {1,2,...,4}
                \draw[-latex'] (demb\x) to (dec\x);
            \foreach \x in {1,2,...,4}
                \draw[-latex'] (dec\x.north) to ([yshift=0.5\base]dec\x.north);
            \foreach \x [count=\y from 2] in {1,2,...,3}
            {
                \draw[-latex'] (enc\x.east) to (enc\y.west);
                \draw[-latex'] (dec\x.east) to (dec\y.west);
            }
            \coordinate (bridge) at ([yshift=-1.15\base]demb2);
          \draw[-latex'] (enc4.north) .. controls +(north:0.4\base) and +(east:0.5\base) .. (bridge) .. controls +(west:2.4\base) and +(west:0.5\base) .. (dec1.west);

        \end{scope}
    \end{tikzpicture}


































