figure-greedy-MT-decoding-2.tex 9.03 KB
Newer Older
曹润柘 committed
1 2 3 4 5 6 7

%%% outline
%-------------------------------------------------------------------------


\begin{tikzpicture}

8
{\footnotesize
曹润柘 committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

\node [anchor=north west,inner sep=2pt,align=left] (line1) at (0,0) {\textrm{\textbf{Function} \textsc{WordDecoding}($s$)}};
\node [anchor=north west,inner sep=2pt,align=left] (line2) at ([yshift=-1pt]line1.south west) {\textrm{1: $\pi = $\textsc{GetTransOptions}($s$)}};
\node [anchor=north west,inner sep=2pt,align=left] (line3) at ([yshift=-1pt]line2.south west) {\textrm{2: $best = \phi$}};
\node [anchor=north west,inner sep=2pt,align=left] (line4) at ([yshift=-1pt]line3.south west) {\textrm{3: \textbf{for} $i$ in $[1,m]$ \textbf{do}}};
\node [anchor=north west,inner sep=2pt,align=left] (line5) at ([yshift=-1pt]line4.south west) {\textrm{4: \hspace{1em} $h = \phi$}};
\node [anchor=north west,inner sep=2pt,align=left] (line6) at ([yshift=-1pt]line5.south west) {\textrm{5: \hspace{1em} \textbf{foreach} $j$ in $[1,m]$ \textbf{do}}};
\node [anchor=north west,inner sep=2pt,align=left] (line7) at ([yshift=-1pt]line6.south west) {\textrm{6: \hspace{2em} \textbf{if} $used[j]=$ \textbf{true} \textbf{then}}};
\node [anchor=north west,inner sep=2pt,align=left] (line8) at ([yshift=-1pt]line7.south west) {\textrm{7: \hspace{3em} $h = h \cup \textrm{\textsc{Join}}(best,\pi[j])$}};
\node [anchor=north west,inner sep=2pt,align=left] (line9) at ([yshift=-1pt]line8.south west) {\textrm{8: \hspace{1em} $best = \textrm{\textsc{PruneForTop1}}(h)$}};
\node [anchor=north west,inner sep=2pt,align=left] (line10) at ([yshift=-1pt]line9.south west) {\textrm{9: \hspace{1em} $used[best.j] = \textrm{\textsc{\textbf{true}}}$}};
\node [anchor=north west,inner sep=2pt,align=left] (line11) at ([yshift=-1pt]line10.south west) {\textrm{10: \textbf{return} $best.translatoin$}};

\node [anchor=south west,inner sep=2pt,align=left] (head1) at ([yshift=1pt]line1.north west) {输出: 找的最佳译文};
\node [anchor=south west,inner sep=2pt,align=left] (head2) at ([yshift=1pt]head1.north west) {输入: 源语句子$s=s_1...s_m$};

}

\begin{pgfonlayer}{background}
\node[rectangle,draw=ublue,thick,inner sep=0.2em,fill=white,drop shadow,minimum height=1.6cm] [fit = (head2) (line8) (line11)] (algorithm) {};

%% highlights
%\begin{pgfonlayer}{background}
{
33 34 35 36 37 38
\node[anchor=west,fill=blue!20,minimum height=0.16in,minimum width=1.85in] (line2highlight) at (line2.west) {};
\node[anchor=west,fill=blue!20,minimum height=0.16in,minimum width=1.85in] (line3highlight) at (line3.west) {};
\node[anchor=west,fill=blue!20,minimum height=0.16in,minimum width=1.85in] (line5highlight) at (line5.west) {};
\node[anchor=west,fill=blue!20,minimum height=0.16in,minimum width=1.85in] (line8highlight) at (line8.west) {};
\node[anchor=west,fill=blue!20,minimum height=0.16in,minimum width=1.85in] (line9highlight) at (line9.west) {};
\node[anchor=west,fill=blue!20,minimum height=0.16in,minimum width=1.85in] (line10highlight) at (line10.west) {};
曹润柘 committed
39 40 41 42 43
}
%\end{pgfonlayer}

\end{pgfonlayer}

44
{
曹润柘 committed
45 46 47

%% remark 1
\begin{scope}
48 49
{\footnotesize
\node [anchor=north west,align=left] (remark1) at ([xshift=0.6in,yshift=-0.8em]algorithm.north east) {获取每个单词\\的翻译候选};
曹润柘 committed
50

51
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=2.1pt,red] (s1) at ([yshift=-0.3em,xshift=0.5em]remark1.north east){1};
52 53 54 55
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=2.1pt,ugreen] (s2) at ([xshift=0.4em]s1.east) {2};
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=2.1pt,orange] (s3) at ([xshift=0.4em]s2.east) {3};
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=3.0pt,ublue] (s4) at ([xshift=0.4em]s3.east) {...};
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=1.5pt,purple] (s5) at ([xshift=0.4em]s4.east) {$m$};
曹润柘 committed
56

57 58 59 60 61
\node [anchor=center,draw,thick,circle,minimum size=0.3em,inner sep=2pt,red,fill=red] (t1) at ([yshift=-2.2em]s1.center) {{\color{white} $n$}};
\node [anchor=center,draw,thick,circle,minimum size=0.3em,inner sep=2pt,ugreen,fill=ugreen] (t2) at ([yshift=-2.2em]s2.center) {{\color{white} $n$}};
\node [anchor=center,draw,thick,circle,minimum size=0.3em,inner sep=2pt,orange,fill=orange] (t3) at ([yshift=-2.2em]s3.center) {{\color{white} $n$}};
\node [anchor=center,draw,thick,circle,minimum size=0.3em,inner sep=2pt,ublue,fill=ublue] (t4) at ([yshift=-2.2em]s4.center) {{\color{white} $n$}};
\node [anchor=center,draw,thick,circle,minimum size=0.3em,inner sep=2pt,purple,fill=purple] (t5) at ([yshift=-2.2em]s5.center) {{\color{white} $n$}};
曹润柘 committed
62 63 64 65 66 67 68 69 70

\draw [->,thick] ([yshift=-0.1em]s1.south) -- ([yshift=0.1em]t1.north);
\draw [->,thick] ([yshift=-0.1em]s2.south) -- ([yshift=0.1em]t2.north);
\draw [->,thick] ([yshift=-0.1em]s3.south) -- ([yshift=0.1em]t3.north);
\draw [->,thick] ([yshift=-0.1em]s4.south) -- ([yshift=0.1em]t4.north);
\draw [->,thick] ([yshift=-0.1em]s5.south) -- ([yshift=0.1em]t5.north);

\begin{pgfonlayer}{background}
{
71
\node[rectangle,draw,inner sep=0.2em,fill=blue!10,minimum width=2.4in] [fit = (remark1) (s1) (t5)] (remark1label) {};
曹润柘 committed
72 73 74 75 76 77 78 79
}
\end{pgfonlayer}
}
\end{scope}
%% end of remark 1

%% remark 2
\begin{scope}
80 81
{\footnotesize
\node [anchor=north west,draw,inner sep=2pt,fill=blue!10,minimum width=2.4in] (remark2) at ([yshift=-0.5em]remark1label.south west) {$best$用于保存当前最好的翻译结果};
曹润柘 committed
82 83 84 85 86 87
}
\end{scope}
%% end of remark 2

%% remark 3
\begin{scope}
88 89
{\footnotesize
\node [anchor=north west,draw,inner sep=2pt,fill=blue!10,minimum width=2.4in] (remark3) at ([yshift=-0.5em]remark2.south west) {$h$用于保存每步生成的所有译文候选};
曹润柘 committed
90 91 92 93 94 95
}
\end{scope}
%% end of remark 3

%% remark 4
\begin{scope}
96 97
{\footnotesize
\node [anchor=north west,inner sep=2pt,align=left] (remark4) at ([xshift=0.7em,yshift=-0.8em]remark3.south west) {\textsc{Join}($a,b$) 返回\\$a$$b$ 的所有组合};
曹润柘 committed
98

99 100
{
\node [anchor=north west,inner sep=1pt,align=center,draw] (a1) at ([yshift=-0.2em]remark4.north east) {a1\\a2};
曹润柘 committed
101 102 103 104 105 106 107 108
\node [anchor=west] (join) at (a1.east) {$\times$};
\node [anchor=north west,inner sep=1pt,align=center,draw] (b1) at ([xshift=1.5em]a1.north east) {b1\\b2};
\node [anchor=west] (join) at (b1.east) {$=$};
\node [anchor=north west,inner sep=1pt,align=center,draw] (result) at ([xshift=1.5em]b1.north east) {a1b1 a1b2\\a2b1 a2b2};
}

\begin{pgfonlayer}{background}
{
109
\node[rectangle,draw,inner sep=2pt,fill=blue!10,minimum width=2.4in] [fit = (remark4) (result)] (remark4label) {};
曹润柘 committed
110 111 112 113 114 115 116 117
}
\end{pgfonlayer}
}
\end{scope}
%% end of remark 4

%% remark 5
\begin{scope}
118 119 120
{\footnotesize
\node [anchor=north west,align=left] (remark5) at ([xshift=0.3em,yshift=-1.6em]remark4.south west) {\textsc{PruneForTop1}\\保留得分最高的结果};
\node [anchor=west,draw,inner sep=1pt] (s1) at ([yshift=-0.2em,xshift=1.2em]remark5.north east){0.234};
121 122
\node [anchor=north west,draw,inner sep=1pt] (s2) at ([yshift=-0.2em]s1.south west){0.197};
\node [anchor=north west,draw,inner sep=1pt] (s3) at ([yshift=-0.2em]s2.south west){0.083};
曹润柘 committed
123 124

\draw [-] ([yshift=-0.1em,xshift=-0.2em]s1.south west) -- ([yshift=-0.1em,xshift=3em]s1.south east);
125
\node [anchor=west] (top1) at ([xshift=0.1em]s1.east) {\color{red}{$\gets$ top1}};
曹润柘 committed
126 127 128

\begin{pgfonlayer}{background}
{
129
\node[rectangle,draw,inner sep=0.2em,fill=blue!10,minimum width=2.4in] [fit = (remark5) (s3) (top1)] (remark5label) {};
曹润柘 committed
130 131 132 133
}
\end{pgfonlayer}
}
\end{scope}
134
% end of remark 5
曹润柘 committed
135 136 137

%% remark 6
\begin{scope}
138 139
{\footnotesize
\node [anchor=north west,align=left] (remark6) at ([xshift=-0.3em,yshift=-1.3em]remark5.south west) {记录已经翻译过\\的源语单词};
曹润柘 committed
140

141 142 143 144 145
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=2.1pt,red] (s1) at ([yshift=-1.3em,xshift=0.5em]remark6.north east){1};
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=2.1pt,ugreen] (s2) at ([xshift=0.4em]s1.east) {2};
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=2.1pt,orange] (s3) at ([xshift=0.4em]s2.east) {3};
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=3.0pt,ublue] (s4) at ([xshift=0.4em]s3.east) {...};
\node [anchor=west,draw,thick,circle,minimum size=0.3em,inner sep=1.5pt,purple] (s5) at ([xshift=0.4em]s4.east) {$m$};
曹润柘 committed
146 147 148 149 150 151

\draw [-,thick,red] (s1.north east) -- (s1.south west);
\draw [-,thick,orange] (s3.north east) -- (s3.south west);

\begin{pgfonlayer}{background}
{
152
\node[rectangle,draw,inner sep=0.2em,fill=blue!10,minimum width=2.4in] [fit = (remark6) (s5)] (remark6label) {};
曹润柘 committed
153 154 155 156
}
\end{pgfonlayer}
}
\end{scope}
157
% end of remark 6
曹润柘 committed
158 159 160 161 162

{
\draw [->,thick] (line2highlight.east) ..controls +(east:1em) and +(west:1em).. (remark1label.west);
}
{
163 164
\draw [->,thick] (line3highlight.east) ..controls +(east:1em) and +(west:1em).. ([yshift=0.0em]remark2.west);
\draw [->,thick] (line5highlight.east) ..controls +(east:1em) and +(west:1em).. ([yshift=0.0em]remark3.west);
曹润柘 committed
165 166
}
{
167
\draw [->,thick] (line8highlight.east) ..controls +(east:1em) and +(west:1em).. ([yshift=1.2em]remark4label.south west);
曹润柘 committed
168 169
}
{
170
\draw [->,thick] (line9highlight.east) ..controls +(east:1em) and +(west:1em).. ([yshift=1.6em]remark5label.south west);
曹润柘 committed
171 172
}
{
173
\draw [->,thick] (line10highlight.east) ..controls +(east:1em) and +(west:1em).. ([yshift=0.0em]remark6label.west);
曹润柘 committed
174 175 176 177 178 179 180 181 182 183 184
}
}

\end{tikzpicture}



%---------------------------------------------------------------------