Commit 69f62c2d by 孟霞

合并分支 'caorunzhe' 到 'mengxia'

Caorunzhe

查看合并请求 !564
parents 84477c81 ed5da23d
...@@ -23,6 +23,22 @@ ...@@ -23,6 +23,22 @@
\chapter{神经机器翻译模型推断} \chapter{神经机器翻译模型推断}
\parinterval 神经机器翻译的一个关键步骤是对神经网络进行训练。也就是,在双语平行数据上优化训练目标函数,使模型参数自动调整到一个“最佳”状态,从而可以对新的句子进行翻译。通常,训练过程对模型性能的好坏起到关键性作用。因此,对模型训练方法的研究也机器翻译领域的重要研究方向,其中的很多发现也对其它自然语言处理任务有很好的借鉴意义。
\parinterval 神经机器翻译模型训练面临着一些挑战,例如:
\begin{itemize}
\vspace{0.5em}
\item 如何对大容量模型进行有效的训练?例如,避免过拟合问题,并让模型更加健壮,同时有效地处理更大的词汇表;
\vspace{0.5em}
\item 如何设计更好的模型训练策略?例如,在训练中更好地利用机器翻译评价指标,同时选择对翻译更有价值的样本进行参数更新;
\vspace{0.5em}
\item 如何让模型学习到的“知识”在模型之间迁移?例如,把一个“强”模型的能力迁移到一个“弱”模型上,而这种能力可能是无法通过直接训练“弱”模型得到的。
\vspace{0.5em}
\end{itemize}
\parinterval 本章将就这些问题展开讨论,内容会覆盖开放词表、正则化、对抗样本训练、最小风险训练、知识蒸馏等多个主题。需要注意的是,神经机器翻译模型训练涉及的内容十分广泛。很多情况下,模型训练问题会和建模问题强相关。因此,本章的内容主要集中在相对独立的模型训练问题上。在后续章节中,仍然会有模型训练方面的介绍,其主要针对机器翻译的特定主题,如极深神经网络训练、无指导训练等。
%---------------------------------------------------------------------------------------- %----------------------------------------------------------------------------------------
% NEW SECTION % NEW SECTION
%---------------------------------------------------------------------------------------- %----------------------------------------------------------------------------------------
...@@ -52,9 +68,11 @@ ...@@ -52,9 +68,11 @@
\parinterval 如果要覆盖更多的翻译现象,词表会不断膨胀,并带来两个问题: \parinterval 如果要覆盖更多的翻译现象,词表会不断膨胀,并带来两个问题:
\begin{itemize} \begin{itemize}
\vspace{0.5em}
\item 数据稀疏。很多不常见的低频词包含在词表中,而这些低频词的分布式表示很难得到充分学习; \item 数据稀疏。很多不常见的低频词包含在词表中,而这些低频词的分布式表示很难得到充分学习;
\vspace{0.5em}
\item 词向量矩阵的增大。这会增加计算和存储的负担。 \item 词向量矩阵的增大。这会增加计算和存储的负担。
\vspace{0.5em}
\end{itemize} \end{itemize}
\parinterval 理想情况下,机器翻译应该是一个{\small\bfnew{开放词表}}\index{开放词表}(Open-Vocabulary)\index{Open-Vocabulary}的翻译任务。也就是,不论测试数据中包含什么样的词,机器翻译系统都应该能够正常翻译。但是,现实的情况是,即使不断扩充词表,也不可能覆盖所有可能的单词。这时就会出现OOV问题(集外词问题)。这个问题在使用受限词表时会更加严重,因为低频词和未见过的词都会被看作OOV单词。这时会将这些单词用<UNK>代替。通常,数据中<UNK>的数量会直接影响翻译性能,过多的<UNK>会造成欠翻译、结构混乱等问题。因此神经机器翻译需要额外的机制解决大词表和OOV问题。 \parinterval 理想情况下,机器翻译应该是一个{\small\bfnew{开放词表}}\index{开放词表}(Open-Vocabulary)\index{Open-Vocabulary}的翻译任务。也就是,不论测试数据中包含什么样的词,机器翻译系统都应该能够正常翻译。但是,现实的情况是,即使不断扩充词表,也不可能覆盖所有可能的单词。这时就会出现OOV问题(集外词问题)。这个问题在使用受限词表时会更加严重,因为低频词和未见过的词都会被看作OOV单词。这时会将这些单词用<UNK>代替。通常,数据中<UNK>的数量会直接影响翻译性能,过多的<UNK>会造成欠翻译、结构混乱等问题。因此神经机器翻译需要额外的机制解决大词表和OOV问题。
...@@ -128,11 +146,13 @@ ...@@ -128,11 +146,13 @@
\parinterval\ref{fig:7-9}给出了BPE算法执行的实例。在执行合并操作时,需要考虑不同的情况。假设词表中存在子词``ab''和``cd'',此时要加入子词``abcd''。可能会出现如下的情况: \parinterval\ref{fig:7-9}给出了BPE算法执行的实例。在执行合并操作时,需要考虑不同的情况。假设词表中存在子词``ab''和``cd'',此时要加入子词``abcd''。可能会出现如下的情况:
\begin{itemize} \begin{itemize}
\vspace{0.5em}
\item 若``ab''、``cd''、``abcd''完全独立,彼此的出现互不影响,将``abcd''加入词表,词表数目$+1$ \item 若``ab''、``cd''、``abcd''完全独立,彼此的出现互不影响,将``abcd''加入词表,词表数目$+1$
\vspace{0.5em}
\item 若``ab''和``cd''必同时出现则词表中加入``abcd'',去除``ab''和``cd'',词表数目$-1$。这个操作是为了较少词表中的冗余; \item 若``ab''和``cd''必同时出现则词表中加入``abcd'',去除``ab''和``cd'',词表数目$-1$。这个操作是为了较少词表中的冗余;
\vspace{0.5em}
\item 若出现``ab'',其后必出现``cd'',但是``cd''却可以作为独立的子词出现,则将``abcd''加入词表,去除``ab'',反之亦然,词表数目不变。 \item 若出现``ab'',其后必出现``cd'',但是``cd''却可以作为独立的子词出现,则将``abcd''加入词表,去除``ab'',反之亦然,词表数目不变。
\vspace{0.5em}
\end{itemize} \end{itemize}
\parinterval 在得到了子词词表后,便需要对单词进行切分。BPE要求从较长的子词开始替换。首先,对子词词表按照字符长度从大到小进行排序。然后,对于每个单词,遍历子词词表,判断每个子词是不是当前词的子串,若是则进行替换切分。将单词中所有的子串替换为子词后,如果仍有子串未被替换,则将其用<UNK>代替,如图\ref{fig:7-10} \parinterval 在得到了子词词表后,便需要对单词进行切分。BPE要求从较长的子词开始替换。首先,对子词词表按照字符长度从大到小进行排序。然后,对于每个单词,遍历子词词表,判断每个子词是不是当前词的子串,若是则进行替换切分。将单词中所有的子串替换为子词后,如果仍有子串未被替换,则将其用<UNK>代替,如图\ref{fig:7-10}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
\begin{tikzpicture} \begin{tikzpicture}
\tikzstyle{bignode} = [line width=0.6pt,draw=black,minimum width=6.3em,minimum height=2.2em,fill=white] \tikzstyle{bignode} = [,inner sep=0.3em,draw=black,line width=0.6pt,rounded corners=2pt,minimum width=3.0em]
\tikzstyle{middlenode} = [line width=0.6pt,draw=black,minimum width=5.6em,minimum height=2.2em,fill=white]
\node [anchor=center] (node1-1) at (0,0) {\scriptsize{汉语}}; \node [anchor=center] (node1-1) at (0,0) {{汉语}};
\node [anchor=west] (node1-2) at ([xshift=0.8em]node1-1.east) {\scriptsize{英语}}; \node [anchor=west] (node1-2) at ([xshift=0.8em]node1-1.east) {{英语}};
\node [anchor=north] (node1-3) at ([xshift=1.45em]node1-1.south) {\scriptsize{反向翻译模型}}; \node [anchor=north] (node1-3) at ([xshift=1.75em]node1-1.south) {{反向翻译模型}};
\draw [->,line width=0.6pt](node1-1.east)--(node1-2.west); \draw [->,thick](node1-1.east)--(node1-2.west);
\begin{pgfonlayer}{background} \begin{pgfonlayer}{background}
{ {
\node[fill=blue!20,inner sep=0.1em,draw=black,line width=0.6pt,minimum width=6.0em,drop shadow,rounded corners=2pt] [fit =(node1-1)(node1-2)(node1-3)] (remark1) {}; \node[fill=blue!20,inner sep=0.3em,draw=black,line width=0.6pt,minimum width=6.0em,drop shadow,rounded corners=2pt] [fit =(node1-1)(node1-2)(node1-3)] (remark1) {};
} }
\end{pgfonlayer} \end{pgfonlayer}
\node [anchor=north,fill=green!20,inner sep=0.1em,minimum width=3em,draw=black,line width=0.6pt,rounded corners=2pt](node2-1) at ([xshift=-1.5em,yshift=-1.95em]remark1.south){\scriptsize{汉语}}; \node [anchor=north,fill=green!20,bignode](node2-1) at ([yshift=-3em]node1-3.south){{汉语}};
\node [anchor=west,fill=green!20,inner sep=0.1em,minimum width=3em,draw=black,line width=0.6pt,rounded corners=2pt](node2-2) at (node2-1.east){\scriptsize{英语}}; \node [anchor=north,fill=green!20,bignode](node2-2) at (node2-1.south){{英语}};
\draw [->,line width=0.6pt]([yshift=-2.0em]remark1.south)--(remark1.south) node [pos=0.5,right] (pos1) {\scriptsize{训练}}; \draw [->,thick](node2-1.north)--(remark1.south) node [pos=0.5,right] (pos1) {{训练}};
\node [anchor=west,fill=yellow!20,inner sep=0.1em,minimum width=3em,draw=black,line width=0.6pt,rounded corners=2pt](node3-1) at ([xshift=5.0em,yshift=0.0em]node1-2.east){\scriptsize{汉语}}; \node [anchor=west,fill=yellow!20,bignode](node3-1) at ([xshift=6.5em,yshift=0.0em]node1-2.east){{汉语}};
\node [anchor=north,fill=red!20,inner sep=0.1em,minimum width=3em,draw=black,line width=0.6pt,rounded corners=2pt](node3-2) at ([yshift=-2.15em]node3-1.south){\scriptsize{英语}}; \node [anchor=north,fill=red!20,bignode](node3-2) at ([yshift=-2.5em]node3-1.south){{英语}};
\node [anchor=center](node3-3) at ([xshift=0.4em]node3-2.east){};
\draw [->,line width=0.6pt](node3-1.south)--(node3-2.north) node [pos=0.5,right] (pos2) {\scriptsize{翻译}}; \draw [->,thick](node3-1.south)--(node3-2.north) node [pos=0.5,right] (pos2) {{翻译}};
\begin{pgfonlayer}{background} \begin{pgfonlayer}{background}
{ {
\node[rounded corners=2pt,inner sep=0.3em,draw=black,line width=0.6pt,dotted] [fit =(node3-1)(node3-2)] (remark2) {}; \node[rounded corners=2pt,inner sep=0.3em,draw=black,line width=0.6pt,dotted] [fit =(node3-1)(node3-2)(node3-3)] (remark2) {};
} }
\end{pgfonlayer} \end{pgfonlayer}
\draw [->,line width=0.6pt](remark1.east)--([yshift=0.85em]remark2.west) node [pos=0.5,above] (pos2) {\scriptsize{模型翻译}}; \draw [->,thick](remark1.east)--([xshift=5.5em]remark1.east) node [pos=0.5,above] (pos2) {{模型翻译}};
\node [anchor=south](pos2-2) at ([yshift=-0.5em]pos2.north){\scriptsize{使用反向}}; \node [anchor=south](pos2-2) at ([yshift=-0.5em]pos2.north){{使用反向}};
\draw[decorate,thick,decoration={brace,amplitude=5pt}] ([yshift=1.3em,xshift=1.0em]node3-1.east) -- ([yshift=-5.2em,xshift=1.0em]node3-1.east) node [pos=0.1,right,xshift=0.0em,yshift=0.0em] (label1) {\scriptsize{{混合}}}; \draw[decorate,thick,decoration={brace,amplitude=5pt}] ([yshift=1.5em,xshift=1.5em]node3-1.east) -- ([yshift=-8.6em,xshift=1.5em]node3-1.east) node [pos=0.1,right,xshift=0.0em,yshift=0.0em] (label1) {{{混合}}};
\node [anchor=west,fill=red!20,inner sep=0.1em,minimum width=3em,draw=black,line width=0.6pt,rounded corners=2pt](node4-1) at ([xshift=2.0em,yshift=1.6em]node3-2.east){\scriptsize{英语}}; \node [anchor=west,fill=red!20,bignode](node4-1) at ([xshift=2.5em,yshift=1.3em]node3-2.east){{英语}};
\node [anchor=north,fill=green!20,inner sep=0.1em,minimum width=3em,draw=black,line width=0.6pt,rounded corners=2pt](node4-2) at (node4-1.south){\scriptsize{}}; \node [anchor=north,fill=yellow!20,bignode](node4-2) at (node4-1.south){{}};
\node [anchor=west,fill=yellow!20,inner sep=0.1em,minimum width=3em,draw=black,line width=0.6pt,rounded corners=2pt](node4-3) at (node4-1.east){\scriptsize{}}; \node [anchor=west,fill=green!20,bignode](node4-3) at (node4-1.east){{}};
\node [anchor=north,fill=green!20,inner sep=0.1em,minimum width=3em,draw=black,line width=0.6pt,rounded corners=2pt](node4-4) at (node4-3.south){\scriptsize{汉语}}; \node [anchor=north,fill=green!20,bignode](node4-4) at (node4-3.south){{汉语}};
\node [anchor=center] (node5-1) at ([xshift=3.4em,yshift=0.25em]node4-3.east) {\scriptsize{英语}}; \node [anchor=center] (node5-1) at ([xshift=5em,yshift=0.02em]node4-3.east) {{英语}};
\node [anchor=west] (node5-2) at ([xshift=0.8em]node5-1.east) {\scriptsize{汉语}}; \node [anchor=west] (node5-2) at ([xshift=0.8em]node5-1.east) {{汉语}};
\node [anchor=north] (node5-3) at ([xshift=1.65em]node5-1.south) {\scriptsize{正向翻译模型}}; \node [anchor=north] (node5-3) at ([xshift=1.65em]node5-1.south) {{正向翻译模型}};
\draw [->,line width=0.6pt](node5-1.east)--(node5-2.west); \draw [->,thick](node5-1.east)--(node5-2.west);
\begin{pgfonlayer}{background} \begin{pgfonlayer}{background}
{ {
\node[fill=blue!20,inner sep=0.1em,draw=black,line width=0.6pt,minimum width=6.0em,drop shadow,rounded corners=2pt] [fit =(node5-1)(node5-2)(node5-3)] (remark3) {}; \node[fill=blue!20,inner sep=0.3em,draw=black,line width=0.6pt,minimum width=6.0em,drop shadow,rounded corners=2pt] [fit =(node5-1)(node5-2)(node5-3)] (remark3) {};
} }
\end{pgfonlayer} \end{pgfonlayer}
\draw [->,line width=0.6pt]([xshift=-2em]remark3.west)--(remark3.west) node [pos=0.5,above] (pos3) {\scriptsize{训练}}; \draw [->,thick]([xshift=-3.2em]remark3.west)--(remark3.west) node [pos=0.5,above] (pos3) {{训练}};
\node [anchor=south](d1) at ([xshift=0.0em,yshift=2em]remark3.north){\scriptsize{真实数据:}};
\node [anchor=north](d2) at ([xshift=0.35em]d1.south){\scriptsize{伪数据:}};
\node [anchor=south](d3) at ([xshift=0.0em,yshift=0em]d1.north){\scriptsize{额外数据:}};
\node [anchor=west,fill=green!20,minimum width=1em](d1-1) at ([xshift=-0.0em]d1.east){};
\node [anchor=west,fill=red!20,minimum width=1em](d2-1) at ([xshift=-0.0em]d2.east){};
\node [anchor=west,fill=yellow!20,minimum width=1em](d3-1) at ([xshift=-0.0em]d3.east){};
\node [anchor=south](d1) at ([xshift=-1.5em,yshift=1em]remark1.north){{真实数据:}};
\node [anchor=west](d2) at ([xshift=2.0em]d1.east){{伪数据:}};
\node [anchor=west](d3) at ([xshift=2.0em]d2.east){{额外数据:}};
\node [anchor=west,fill=green!20,minimum width=1.5em](d1-1) at ([xshift=-0.0em]d1.east){};
\node [anchor=west,fill=red!20,minimum width=1.5em](d2-1) at ([xshift=-0.0em]d2.east){};
\node [anchor=west,fill=yellow!20,minimum width=1.5em](d3-1) at ([xshift=-0.0em]d3.east){};
\end{tikzpicture} \end{tikzpicture}
\ No newline at end of file
\begin{tikzpicture} \begin{tikzpicture}
\begin{scope} \tikzstyle{rec} = [inner sep=0.3em,minimum width=4em,draw=black,line width=0.6pt,rounded corners=2pt]
\node [anchor=center] (node1) at (9.6,1) {\small{训练:}}; \node [anchor=north,fill=green!20,rec](node1-1) at (0,0){{汉语}};
\node [anchor=center] (node11) at (10.2,1) {}; \node [anchor=north,fill=green!20,rec](node1-2) at (node1-1.south){{英语}};
\node [anchor=center] (node12) at (11.4,1) {}; \node [anchor=north,fill=yellow!20,rec](node2-1) at ([yshift=-5.0em]node1-1.south){{汉语}};
\node [anchor=center] (node2) at (9.6,0.5) {\small{推理:}}; \node [anchor=north,fill=red!20,rec](node2-2) at (node2-1.south){{英语}};
\node [anchor=center] (node21) at (10.2,0.5) {}; \node [anchor=east] (node3-1) at ([xshift=-4.0em,yshift=-3.5em]node1-1.west) {{正向}};
\node [anchor=center] (node22) at (11.4,0.5) {}; \node [anchor=north] (node3-2) at ([yshift=0.5em]node3-1.south) {{翻译模型}};
\node [anchor=west,draw=black,line width=0.6pt,minimum width=5.6em,minimum height=2.2em,fill=blue!20,rounded corners=2pt] (node1-1) at (0,0) {\footnotesize{双语数据}}; \begin{pgfonlayer}{background}
\node [anchor=south,draw=black,line width=0.6pt,minimum width=4.5em,minimum height=2.2em,fill=blue!20,rounded corners=2pt] (node1-2) at ([yshift=-5em]node1-1.south) {\footnotesize{目标语伪数据}}; {
\node [anchor=west,draw=black,line width=0.6pt,minimum width=4.5em,minimum height=2.2em,fill=red!20,rounded corners=2pt] (node2-1) at ([xshift=-7.7em,yshift=-2.5em]node1-1.west) {\footnotesize{前向NMT系统}}; \node[fill=blue!20,inner sep=0.3em,draw=black,line width=0.6pt,minimum width=3.0em,drop shadow,rounded corners=2pt] [fit =(node3-1)(node3-2)] (remark1) {};
\node [anchor=west,draw=black,line width=0.6pt,minimum width=4.5em,minimum height=2.2em,fill=red!20,rounded corners=2pt] (node3-1) at ([xshift=1.5em,yshift=-2.5em]node1-1.east) {\footnotesize{反向NMT系统}}; }
\end{pgfonlayer}
\draw [->,thick]([yshift=-0.75em]node1-1.west)--(remark1.north east);
\draw [->,thick,dashed](remark1.south east)--([yshift=-0.75em]node2-1.west);
\node [anchor=east,draw=black,line width=0.6pt,minimum width=5.6em,minimum height=2.2em,fill=blue!20,rounded corners=2pt] (node4-1) at ([xshift=18em]node1-1) {\footnotesize{双语数据}}; \node [anchor=west] (node4-1) at ([xshift=4.0em,yshift=-3.5em]node1-1.east) {{反向}};
\node [anchor=south,draw=black,line width=0.6pt,minimum width=4.5em,minimum height=2.2em,fill=blue!20,rounded corners=2pt] (node4-2) at ([yshift=-5em]node4-1.south) {\footnotesize{目标语伪数据}}; \node [anchor=north] (node4-2) at ([yshift=0.5em]node4-1.south) {{翻译模型}};
\begin{pgfonlayer}{background}
{
\node[fill=blue!20,inner sep=0.3em,draw=black,line width=0.6pt,minimum width=3.0em,drop shadow,rounded corners=2pt] [fit =(node4-1)(node4-2)] (remark2) {};
}
\end{pgfonlayer}
\draw [->,thick]([yshift=-0.75em]node1-1.east)--(remark2.north west);
\draw [->,thick]([yshift=-0.75em]node2-1.east)--(remark2.south west);
\node [anchor=east,draw=black,line width=0.6pt,minimum width=4.5em,minimum height=2.2em,fill=red!20,rounded corners=2pt] (node5-1) at ([xshift=15.2em]node3-1.east) {\footnotesize{前向NMT系统}}; \node [anchor=west,fill=green!20,rec](node5-1) at ([xshift=4.0em,yshift=3.48em]node4-1.east){{英语}};
\node [anchor=north,fill=green!20,rec](node5-2) at (node5-1.south){{汉语 }};
\node [anchor=north,fill=yellow!20,rec](node6-1) at ([yshift=-5.0em]node5-1.south){{英语}};
\node [anchor=north,fill=red!20,rec](node6-2) at (node6-1.south){{汉语}};
\draw [->,thick,dashed](remark2.south east)--([yshift=-0.75em]node6-1.west);
\node [anchor=west] (node7-1) at ([xshift=4.0em,yshift=-3.5em]node5-1.east) {{正向}};
\node [anchor=north] (node7-2) at ([yshift=0.5em]node7-1.south) {{翻译模型}};
\begin{pgfonlayer}{background}
{
\node[fill=blue!20,inner sep=0.3em,draw=black,line width=0.6pt,minimum width=3.0em,drop shadow,rounded corners=2pt] [fit =(node7-1)(node7-2)] (remark3) {};
}
\end{pgfonlayer}
\draw [->,thick]([yshift=-0.75em]node5-1.east)--(remark3.north west);
\draw [->,thick]([yshift=-0.75em]node6-1.east)--(remark3.south west);
\node [anchor=south](d1) at ([xshift=-0.7em,yshift=4em]remark1.north){{真实数据:}};
\node [anchor=west](d2) at ([xshift=2.0em]d1.east){{伪数据:}};
\node [anchor=west](d3) at ([xshift=2.0em]d2.east){{额外数据:}};
\node [anchor=west,fill=green!20,minimum width=1.5em](d1-1) at ([xshift=-0.0em]d1.east){};
\node [anchor=west,fill=red!20,minimum width=1.5em](d2-1) at ([xshift=-0.0em]d2.east){};
\node [anchor=west,fill=yellow!20,minimum width=1.5em](d3-1) at ([xshift=-0.0em]d3.east){};
\node [anchor=south] (d4) at ([xshift=1em]d1.north) {{训练:}};
\node [anchor=south] (d5) at ([xshift=0.5em]d2.north) {{推理:}};
\draw [->,thick] ([xshift=0em]d4.east)--([xshift=1.5em]d4.east);
\draw [->,thick,dashed] ([xshift=0em]d5.east)--([xshift=1.5em]d5.east);
\draw [->,line width=1pt](node1-1.west)--([xshift=3em]node2-1.north);
\draw [->,line width=1pt](node1-1.east)--([xshift=-3em]node3-1.north);
\draw [->,line width=1pt](node1-2.east)--([xshift=-3em]node3-1.south);
\draw [->,line width=1pt](node11.east)--(node12.west);
\draw [->,line width=1pt,dashed](node21.east)--(node22.west);
\draw [->,line width=1pt,dashed]([xshift=3em]node2-1.south)--([xshift=-0.1em]node1-2.west);
\draw [->,line width=1pt,dashed]([xshift=3em]node3-1.south)--([xshift=-0.1em]node4-2.west);
\draw [->,line width=1pt](node4-1.east)--([xshift=-3em]node5-1.north);
\draw [->,line width=1pt](node4-2.east)--([xshift=-3em]node5-1.south);
\end{scope}
\end{tikzpicture} \end{tikzpicture}
\ No newline at end of file
\definecolor{color1}{rgb}{1,0.725,0.058}
\tikzstyle{data} = [rectangle,very thick,rounded corners,minimum width=2.3cm,minimum height=0.83cm,text centered,draw=black!70,fill=color1!25]
\tikzstyle{data_shadow} = [rectangle,very thick,rounded corners,minimum width=2.3cm,minimum height=0.83cm,text centered,draw=black!70,fill=black!70]
\tikzstyle{process} = [rectangle,thick,rounded corners,minimum width=2cm,minimum height=0.7cm,text centered,draw=black!80,fill=gray!25]
\tikzstyle{state} = [rectangle,thick,rounded corners,minimum width=3cm,minimum height=0.7cm,text centered,draw=black!80,fill=gray!25]
\begin{tikzpicture}[node distance = 0,scale = 1]
\tikzstyle{every node}=[scale=1]
\node(monolingual_X_shadow)[data_shadow]{};
\node(bilingual_D_shadow)[data_shadow, right of = monolingual_X_shadow, xshift=5cm]{};
\node(monolingual_Y_shadow)[data_shadow, right of = bilingual_D_shadow, xshift=5cm]{};
\node(monolingual_X)[data,right of = monolingual_X_shadow,xshift=-0.08cm,yshift=0.08cm]{单语语料X};
\node(bilingual_D)[data, right of = monolingual_X, xshift=5cm, fill=ugreen!25]{双语语料D};
\node(monolingual_Y)[data, right of = bilingual_D, xshift=5cm, fill=blue!25]{单语语料Y};
\node(process_1_1)[process, right of = monolingual_X, xshift=2.5cm, yshift=-1.5cm]{\textbf{$M^0_{x\to y}$}};
\node(process_1_2)[process, right of = process_1_1, xshift=5cm, fill=red!25]{$M^0_{y\to x}$};
\node(process_2_1)[process, below of = process_1_1, yshift=-1.2cm]{解码过程};
\node(process_2_2)[process, below of = process_1_2, yshift=-1.2cm, fill=red!25]{解码过程};
\node(process_3_1)[state, below of = process_2_1, yshift=-1.2cm, fill=color1!25]{\{$x_i,\hat{y}^0_i$\}};
\node(process_3_2)[state, below of = process_2_2, yshift=-1.2cm, fill=blue!25]{\{$\hat{x}^0_i,{y_i}$\}};
\node(process_4_1)[process, below of = process_3_1, yshift=-1.2cm]{\textbf{$M^1_{x\to y}$}};
\node(process_4_2)[process, below of = process_3_2, yshift=-1.2cm, fill=red!25]{$M^1_{y\to x}$};
\node(process_5_1)[process, below of = process_4_1, yshift=-1.2cm]{解码过程};
\node(process_5_2)[process, below of = process_4_2, yshift=-1.2cm, fill=red!25]{解码过程};
\node(process_6_1)[state, below of = process_5_1, yshift=-1.2cm, fill=color1!25]{\{$x_i,\hat{y}^1_i$\}};
\node(process_6_2)[state, below of = process_5_2, yshift=-1.2cm, fill=blue!25]{\{$\hat{x}^1_i,{y_i}$\}};
\node(process_7_1)[process, below of = process_6_1, yshift=-1.2cm]{\textbf{$M^2_{x\to y}$}};
\node(process_7_2)[process, below of = process_6_2, yshift=-1.2cm, fill=red!25]{$M^2_{y\to x}$};
\node(ellipsis_1)[below of = monolingual_X, yshift=-9.9cm,scale=1.5]{$...$};
\node(ellipsis_2)[below of = process_7_1, yshift=-1.2cm,scale=1.5]{$...$};
\node(ellipsis_3)[below of = bilingual_D, yshift=-9.9cm,scale=1.5]{$...$};
\node(ellipsis_4)[below of = process_7_2, yshift=-1.2cm,scale=1.5]{$...$};
\node(ellipsis_5)[below of = monolingual_Y, yshift=-9.9cm,scale=1.5]{$...$};
\node(text_1)[left of = process_2_1, xshift=-4cm,scale=0.8]{第0轮迭代};
\node(text_2)[left of = process_5_1, xshift=-4cm,scale=0.8]{第1轮迭代};
\node(text_3)[left of = ellipsis_2, xshift=-4cm, scale=0.8]{第2轮迭代};
\draw[->, very thick, color=color1!40](monolingual_X.south)--(ellipsis_1.north);
\draw[->, very thick, color=ugreen!55](bilingual_D.south)--(ellipsis_3.north);
\draw[->, very thick, color=blue!55](monolingual_Y.south)--(ellipsis_5.north);
\draw[->, very thick, color=color1!40]([xshift=-1.5cm]process_2_1.west)--(process_2_1.west);
\draw[->, very thick, color=color1!40]([xshift=-1.5cm]process_5_1.west)--(process_5_1.west);
\draw[->, very thick, color=blue!55]([xshift=1.5cm]process_2_2.east)--(process_2_2.east);
\draw[->, very thick, color=blue!55]([xshift=1.5cm]process_5_2.east)--(process_5_2.east);
\draw[->, thick](process_1_1.south)--(process_2_1.north);
\draw[->, thick](process_1_2.south)--(process_2_2.north);
\draw[->, thick](process_2_1.south)--(process_3_1.north);
\draw[->, thick](process_2_2.south)--(process_3_2.north);
\draw[->, thick](process_4_1.south)--(process_5_1.north);
\draw[->, thick](process_4_2.south)--(process_5_2.north);
\draw[->, thick](process_5_1.south)--(process_6_1.north);
\draw[->, thick](process_5_2.south)--(process_6_2.north);
\draw[->, thick](process_7_1.south)--(ellipsis_2.north);
\draw[->, thick](process_7_2.south)--(ellipsis_4.north);
\draw[->, very thick, color=color1!40](process_3_1.east)--([yshift=0.35cm]process_4_2.west);
\draw[->, very thick, color=color1!40](process_3_2.west)--([yshift=0.35cm]process_4_1.east);
\draw[->, very thick, color=color1!40](process_6_1.east)--([yshift=0.35cm]process_7_2.west);
\draw[->, very thick, color=color1!40](process_6_2.west)--([yshift=0.35cm]process_7_1.east);
\draw[->, very thick, color=ugreen!55,in=0,out=270]([xshift=-0.3cm]bilingual_D.south)to(process_1_1.east);
\draw[->, very thick, color=ugreen!55,in=180,out=270]([xshift=0.3cm]bilingual_D.south)to(process_1_2.west);
\draw[->, very thick, color=ugreen!55,in=0,out=270]([yshift=-3.7cm]bilingual_D.south)to(process_4_1.east);
\draw[->, very thick, color=ugreen!55,in=180,out=270]([yshift=-3.7cm]bilingual_D.south)to(process_4_2.west);
\draw[->, very thick, color=ugreen!55,in=0,out=270]([yshift=-7.3cm]bilingual_D.south)to(process_7_1.east);
\draw[->, very thick, color=ugreen!55,in=180,out=270]([yshift=-7.3cm]bilingual_D.south)to(process_7_2.west);
\draw[->, very thick, color=ugreen!55,in=180,out=270]([yshift=-7.3cm]bilingual_D.south)to(process_7_2.west);
\draw[-, very thick, dashed, color=blue!55]([xshift=-1cm,yshift=-0.35cm]text_1.south)--([xshift=12.7cm,yshift=-0.35cm]text_1.south);
\draw[-, very thick, dashed, color=blue!55]([xshift=-1cm,yshift=-0.35cm]text_2.south)--([xshift=12.7cm,yshift=-0.35cm]text_2.south);
\draw[-, very thick, dashed, color=blue!55]([xshift=-1cm,yshift=-0.35cm]text_3.south)--([xshift=12.7cm,yshift=-0.35cm]text_3.south);
\end{tikzpicture}
\ No newline at end of file
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
\begin{figure}[htp] \begin{figure}[htp]
\centering \centering
\input{./Chapter16/Figures/figure-example-of-iterative-back-translation} \input{./Chapter16/Figures/figure-example-of-iterative-back-translation}
\caption{\red{迭代式回译方法的流程,未修改} {\color{blue} 这个图的逻辑我觉得是ok的,主要是这些线和过程需要再清晰一下,再找我讨论下!}} \caption{迭代式回译方法的流程}
\label{fig:16-2-xc} \label{fig:16-2-xc}
\end{figure} \end{figure}
%---------------------------------------------- %----------------------------------------------
...@@ -288,7 +288,7 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关 ...@@ -288,7 +288,7 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关
%---------------------------------------------- %----------------------------------------------
\begin{figure}[h] \begin{figure}[h]
\centering \centering
\includegraphics[scale=0.7]{Chapter16/Figures/figure-the-iterative-process-of-bidirectional-training.png} \input{Chapter16/Figures/figure-the-iterative-process-of-bidirectional-training}
\caption{双向训练的迭代过程} \caption{双向训练的迭代过程}
\label{fig:16-1-fk} \label{fig:16-1-fk}
\end{figure} \end{figure}
...@@ -315,7 +315,7 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关 ...@@ -315,7 +315,7 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关
\label{eq:16-7-xc} \label{eq:16-7-xc}
\end{eqnarray} \end{eqnarray}
\parinterval 公式\ref{eq:16-7-xc}很自然地把两个方向的翻译模型$\funp{P}(\seq{y}|\seq{x})$$\funp{P}(\seq{x}|\seq{y})$以及两个语言模型$\funp{P}(\seq{x})$$\funp{P}(\seq{y})$联系起来:$\funp{P}(\seq{x})\funp{P}(\seq{y}|\seq{x})$应该与$\funp{P}(\seq{y})\funp{P}(\seq{x}|\seq{y})$接近,因为它们都表达了同一个联合分布$\funp{P}(\seq{x},\seq{y})$。因此,在构建训练两个方向的翻译模型的目标函数时,除了它们单独训练时各自使用的极大似然估计目标函数,可以额外增加一个目标项来鼓励两个方向的翻译模型: \parinterval 公式\eqref{eq:16-7-xc}很自然地把两个方向的翻译模型$\funp{P}(\seq{y}|\seq{x})$$\funp{P}(\seq{x}|\seq{y})$以及两个语言模型$\funp{P}(\seq{x})$$\funp{P}(\seq{y})$联系起来:$\funp{P}(\seq{x})\funp{P}(\seq{y}|\seq{x})$应该与$\funp{P}(\seq{y})\funp{P}(\seq{x}|\seq{y})$接近,因为它们都表达了同一个联合分布$\funp{P}(\seq{x},\seq{y})$。因此,在构建训练两个方向的翻译模型的目标函数时,除了它们单独训练时各自使用的极大似然估计目标函数,可以额外增加一个目标项来鼓励两个方向的翻译模型:
\begin{eqnarray} \begin{eqnarray}
{L}_{\rm{dual}} & = & (\log{\funp{P}(\seq{x})} + \log{\funp{P}(\seq{y}|\seq{x})} - \log{\funp{P}(\seq{y})} - \log{\funp{P}(\seq{x}|\seq{y}))^{2}} {L}_{\rm{dual}} & = & (\log{\funp{P}(\seq{x})} + \log{\funp{P}(\seq{y}|\seq{x})} - \log{\funp{P}(\seq{y})} - \log{\funp{P}(\seq{x}|\seq{y}))^{2}}
\label{eq:16-8-xc} \label{eq:16-8-xc}
...@@ -323,7 +323,7 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关 ...@@ -323,7 +323,7 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关
\parinterval 通过该正则化项,我们将互为对偶的两个任务放在一块学习,通过任务对偶性加强监督学习的过程,就是有监督对偶学习\upcite{DBLP:conf/icml/XiaQCBYL17,qin2020dual}。这里,$\funp{P}(\seq{x})$$\funp{P}(\seq{y})$这两个语言模型是预先训练好的,并不参与翻译模型的训练。可以看到,对于单独的一个模型来说,其目标函数增加了与另外一个方向的模型相关的项。这样的形式与L1/L2正则化非常类似(见{\chapternine}),因此可以把这个方法看作是一种任务特定的正则化的手段(由翻译任务本身的性质所启发而来)。有监督对偶学习实际上要优化下面这个损失函数: \parinterval 通过该正则化项,我们将互为对偶的两个任务放在一块学习,通过任务对偶性加强监督学习的过程,就是有监督对偶学习\upcite{DBLP:conf/icml/XiaQCBYL17,qin2020dual}。这里,$\funp{P}(\seq{x})$$\funp{P}(\seq{y})$这两个语言模型是预先训练好的,并不参与翻译模型的训练。可以看到,对于单独的一个模型来说,其目标函数增加了与另外一个方向的模型相关的项。这样的形式与L1/L2正则化非常类似(见{\chapternine}),因此可以把这个方法看作是一种任务特定的正则化的手段(由翻译任务本身的性质所启发而来)。有监督对偶学习实际上要优化下面这个损失函数:
\begin{eqnarray} \begin{eqnarray}
{L} & = & \log{\funp{P}(\seq{y}|\seq{x})}+\log{\funp{P}(\seq{x}|\seq{y})}+\mathcal{L}_{\rm{dual}} {L} & = & \log{\funp{P}(\seq{y}|\seq{x})}+\log{\funp{P}(\seq{x}|\seq{y})}+{L}_{\rm{dual}}
\label{eq:16-2-fk} \label{eq:16-2-fk}
\end{eqnarray} \end{eqnarray}
...@@ -346,7 +346,7 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关 ...@@ -346,7 +346,7 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关
\label{eq:16-9-xc} \label{eq:16-9-xc}
\end{eqnarray} \end{eqnarray}
\parinterval 公式\ref{eq:16-9-xc}假设$\funp{P}(\seq{x}|\seq{y})=\funp{P}(\seq{x}|\seq{x},\seq{y})$。这个假设显然是成立的,因为当知道一个句子的译文时,并不需要知道它的源文就可以把它翻译回去。如果直接优化(最大化)公式\ref{eq:16-9-xc}右侧,相当于对这个等式$\funp{P}(\seq{x}|\seq{y})$$\funp{P}(\seq{y}|\seq{x})$施加了{\small\sffamily\bfnew{循环一致性}}\index{循环一致性}(Circle Consistency)\index{Circle Consistency}的约束\upcite{DBLP:conf/iccv/ZhuPIE17},也就是对于一个句子$\seq{x}$,通过$\funp{P}(\seq{y}|\seq{x})$把它翻译成$\seq{y}$后,根据$\funp{P}(\seq{x}|\seq{y})$应该能重新翻译出$\seq{x}$,如图\ref{fig:16-10-xc}所示。公式\ref{eq:16-9-xc}给出了同时优化$\funp{P}(\seq{x}|\seq{y})$$\funp{P}(\seq{y}|\seq{x})$的一个目标函数形式。这个目标函数的一个额外的好处是它本质上是在学习一个由$\funp{P}(\seq{x}|\seq{y})$$\funp{P}(\seq{y}|\seq{x})$组成的语言模型$\funp{P}(\seq{x})$,而$\funp{P}(\seq{x})$的学习依赖于单语数据,这意味着这个目标函数可以很自然地直接使用大量单语数据来同时训练两个翻译模型。相同的结论可以推广到$\funp{P}(\seq{y})$\upcite{DBLP:conf/nips/HeXQWYLM16} \parinterval 公式\eqref{eq:16-9-xc}假设$\funp{P}(\seq{x}|\seq{y})=\funp{P}(\seq{x}|\seq{x},\seq{y})$。这个假设显然是成立的,因为当知道一个句子的译文时,并不需要知道它的源文就可以把它翻译回去。如果直接优化(最大化)公式\eqref{eq:16-9-xc}右侧,相当于对这个等式$\funp{P}(\seq{x}|\seq{y})$$\funp{P}(\seq{y}|\seq{x})$施加了{\small\sffamily\bfnew{循环一致性}}\index{循环一致性}(Circle Consistency)\index{Circle Consistency}的约束\upcite{DBLP:conf/iccv/ZhuPIE17},也就是对于一个句子$\seq{x}$,通过$\funp{P}(\seq{y}|\seq{x})$把它翻译成$\seq{y}$后,根据$\funp{P}(\seq{x}|\seq{y})$应该能重新翻译出$\seq{x}$,如图\ref{fig:16-10-xc}所示。公式\eqref{eq:16-9-xc}给出了同时优化$\funp{P}(\seq{x}|\seq{y})$$\funp{P}(\seq{y}|\seq{x})$的一个目标函数形式。这个目标函数的一个额外的好处是它本质上是在学习一个由$\funp{P}(\seq{x}|\seq{y})$$\funp{P}(\seq{y}|\seq{x})$组成的语言模型$\funp{P}(\seq{x})$,而$\funp{P}(\seq{x})$的学习依赖于单语数据,这意味着这个目标函数可以很自然地直接使用大量单语数据来同时训练两个翻译模型。相同的结论可以推广到$\funp{P}(\seq{y})$\upcite{DBLP:conf/nips/HeXQWYLM16}
%---------------------------------------------- %----------------------------------------------
\begin{figure}[htp] \begin{figure}[htp]
...@@ -357,14 +357,14 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关 ...@@ -357,14 +357,14 @@ $\funp{P}(\seq{y}|\seq{x})$和$\funp{P}(\seq{x}|\seq{y})$是否真的没有关
\end{figure} \end{figure}
%---------------------------------------------- %----------------------------------------------
\parinterval 但是直接使用公式\ref{eq:16-9-xc}作为目标函数需要解决两个问题: \parinterval 但是直接使用公式\eqref{eq:16-9-xc}作为目标函数需要解决两个问题:
\begin{itemize} \begin{itemize}
\vspace{0.5em} \vspace{0.5em}
\item 计算公式\ref{eq:16-9-xc}要枚举所有可能的隐变量$\seq{y}$的取值,也就是所有可能产生的目标语句子,而这是不可能的,因此一般会通过平均多个随机产生的$\seq{y}$对应的损失来近似真正的目标函数值; \item 计算公式\eqref{eq:16-9-xc}要枚举所有可能的隐变量$\seq{y}$的取值,也就是所有可能产生的目标语句子,而这是不可能的,因此一般会通过平均多个随机产生的$\seq{y}$对应的损失来近似真正的目标函数值;
\vspace{0.5em} \vspace{0.5em}
\item 从公式\ref{eq:16-9-xc}可以看到,在$\funp{P}(\seq{x})$上计算完目标函数值后,得到的梯度首先传递给$\funp{P}(\seq{x}|\seq{y})$,然后通过$\funp{P}(\seq{x}|\seq{y})$传递给$\funp{P}(\seq{y}|\seq{x})$。由于$\funp{P}(\seq{x}|\seq{y})$的输入$\seq{y}$$\funp{P}(\seq{y}|\seq{x})$采样得到,而采样操作不可导,导致梯度的传播在$\funp{P}(\seq{y}|\seq{x})$的输出处断开了,因此$\funp{P}(\seq{y}|\seq{x})$接收不到任何梯度来进行更新。常见的解决方案是使用策略梯度\upcite{DBLP:conf/nips/SuttonMSM99}。策略梯度的基本思想如下:如果在执行某个动作之后,获得了一个不错的反馈,那么可以调整策略来增加这个状态下执行该动作的概率;反之,如果采取某个动作后获得了一个负反馈,就需要调整策略来降低这个状态下执行该动作的概率。在算法的实现上,首先对两个翻译模型求梯度,然后在策略调整时选择将梯度加到模型上(获得正反馈)或者减去该梯度(获得负反馈)。 \item 从公式\eqref{eq:16-9-xc}可以看到,在$\funp{P}(\seq{x})$上计算完目标函数值后,得到的梯度首先传递给$\funp{P}(\seq{x}|\seq{y})$,然后通过$\funp{P}(\seq{x}|\seq{y})$传递给$\funp{P}(\seq{y}|\seq{x})$。由于$\funp{P}(\seq{x}|\seq{y})$的输入$\seq{y}$$\funp{P}(\seq{y}|\seq{x})$采样得到,而采样操作不可导,导致梯度的传播在$\funp{P}(\seq{y}|\seq{x})$的输出处断开了,因此$\funp{P}(\seq{y}|\seq{x})$接收不到任何梯度来进行更新。常见的解决方案是使用策略梯度\upcite{DBLP:conf/nips/SuttonMSM99}。策略梯度的基本思想如下:如果在执行某个动作之后,获得了一个不错的反馈,那么可以调整策略来增加这个状态下执行该动作的概率;反之,如果采取某个动作后获得了一个负反馈,就需要调整策略来降低这个状态下执行该动作的概率。在算法的实现上,首先对两个翻译模型求梯度,然后在策略调整时选择将梯度加到模型上(获得正反馈)或者减去该梯度(获得负反馈)。
\vspace{0.5em} \vspace{0.5em}
\end{itemize} \end{itemize}
......
...@@ -21,10 +21,159 @@ ...@@ -21,10 +21,159 @@
% CHAPTER 17 % CHAPTER 17
%---------------------------------------------------------------------------------------- %----------------------------------------------------------------------------------------
\chapter{神经机器翻译实践} \chapter{机器翻译应用技术}
\parinterval 近几年,随着翻译品质的不断提升,越来越多的机器翻译需求被挖掘出来。但是,仅凭一个翻译引擎无法满足如此多样的需求。应用机器翻译技术时,需要“额外”考虑很多因素,例如,数据加工方式、交互方式、应用的领域等,甚至机器翻译模型也要经过改造才能适应到不同的场景中。
\parinterval 本章将重点介绍机器翻译应用中所面临的问题,以及解决这些问题可以采用的策略。本章所涉及的内容较为广泛,一方面会大量使用本书前十七章的模型和方法,另一方面也会介绍新的技术手段。最终,本章会结合机器翻译的特点展示机器翻译可能的应用场景,并进行一些对机器翻译未来的思考。
%----------------------------------------------------------------------------------------
% NEW SECTION
%----------------------------------------------------------------------------------------
\section{机器翻译的应用并不简单}
\parinterval 机器翻译一直是自然语言处理的热点,无论从评测比赛的结果,还是论文发表数量上看,机器翻译的研究可谓火热。但是,客观的说,我们离机器翻译完美的应用还有相当的距离。这主要是因为,成熟的系统需要很多技术的融合。因此,机器翻译系统研发也是一项复杂的系统工程。而机器翻译研究大多是对局部模型和方法的调整,这也会造成一个现象,很多论文里报道的技术方法可能无法直接应用于真实场景的系统。因此,需要关注如何对具体的机器翻译应用问题进行求解,使机器翻译技术能够落地。有几方面挑战:
\begin{itemize}
\vspace{0.5em}
\item {\small\bfnew{机器翻译模型很脆弱}}。实验环境下,给定翻译任务,甚至给定训练和测试数据,机器翻译模型可以表现的很好。但是,应用场景是不断变化的。经常会出现训练数据缺乏、应用领域与训练数据不匹配、用户的测试方法与开发者不同等等一系列问题。特别是,对于不同的任务,神经机器翻译等模型需要进行非常细致的调整,理想中一套``包打天下''的模型和设置是不存在的。这些都导致一个结果:直接使用既有机器翻译模型很难满足真实应用的需求。
\vspace{0.5em}
\item {\small\bfnew{机器翻译缺少针对场景的应用技术}}。目前为止,机器翻译的研究进展已经为我们提供很好的机器翻译基础模型。但是,用户并不是简单的与这些模型“打交道”,他们更加关注如何解决自身的业务需求,例如,机器翻译应用的交互方式、系统是否可以自己预估翻译可信度等等。甚至,在某些场景中,用户对翻译模型的体积和速度都有非常严格的要求。
\vspace{0.5em}
\item {\small\bfnew{优秀系统的研发需要长时间的打磨}}。工程打磨也是研发优秀机器翻译系统的必备条件,有些时候甚至是决定性的。从科学研究的角度看,我们需要对更本质的科学问题进行探索,而非简单的工程开发与调试。但是,对一个初级的系统进行研究往往会掩盖掉``真正的问题'',因为很多问题在更优秀的系统中并不存在。
\vspace{0.5em}
\end{itemize}
\parinterval 下面本章将重点对机器翻译应用中的若干技术问题展开讨论,旨在给机器翻译应用提供一些可落地的思路。之后,本章也会结合笔者的经验,对机器翻译的发展方向展开一些讨论。
%----------------------------------------------------------------------------------------
% NEW SECTION
%----------------------------------------------------------------------------------------
\section{增量式模型优化}
\parinterval 机器翻译的训练数据不是一成不变的。系统研发人员可以使用自有数据训练得到基础的翻译模型(或初始模型)。当应用这个基础模型时,可能会有新的数据出现,例如:
\begin{itemize}
\vspace{0.5em}
\item 应用的目标领域和场景可能是系统研发时无法预见的,但是用户会有一定量自有数据,可以用于系统优化。
\vspace{0.5em}
\item 系统在应用中会产生新的数据,这些数据经过一些筛选和修改也可以用于模型训练。
\vspace{0.5em}
\end{itemize}
\parinterval 这时就产生一个问题,能否使用新的数据让系统变得更好?简单直接的方式是,将新的数据和原始数据混合重新训练系统,但是使用全量数据训练模型的周期很长,这种方法的成本很高。而且,新的数据可能是不断产生的,甚至是流式的。这时就需要一种快速、低成本的方式对模型进行更新。
\parinterval 增量训练就是满足上述需求的一种方法。本质上来说,神经机器翻译中使用的随机梯度下降方法就是典型的增量训练方法,其基本思想是:每次选择一个样本对模型进行更新,这个过程反复不断执行,每次模型更新都是一次增量训练。当多个样本构成了一个新数据集时,可以把这些新样本作为训练数据,把当前的模型作为初始模型,之后正常执行机器翻译的训练过程即可。如果新增加的数据量不大(比如,几万句对),训练的代价非常低。
\parinterval 这里面的一个问题是,新的数据虽然能代表一部分的翻译现象,但是如果仅仅依赖新数据进行更新,会使模型对新数据过分拟合,进而造成无法很好地处理新数据之外的样本。这也可以被看做是一种灾难性遗忘的问题({\color{red} 参考文献!}),即:模型过分注重对新样本的拟合,丧失了旧模型的一部分能力。解决这个问题,有几种思路:
\begin{itemize}
\vspace{0.5em}
\item 数据混合。在增量训练时,除了使用新的数据,再混合一定量的旧数据,混合的比例可以根据训练的代价进行调整。这样,模型相当于在全量数据的一个采样结果上进行更新。
\vspace{0.5em}
\item 模型插值({\color{red} 参考文献!})。在增量训练之后,将新模型与旧模型进行插值。
\vspace{0.5em}
\item 多目标训练({\color{red} 参考文献!})。在增量训练时,除了在新数据上定义损失函数之外,可以再定义一个在旧数据上的损失函数,这样确保模型可以在两个数据上都有较好的表现。另一种方案是引入正则化项,使新模型的参数不会偏离旧模型的参数太远。
\vspace{0.5em}
\end{itemize}
\parinterval {\color{red} 图XXX}给出了上述方法的对比。在实际应用中,还有很多细节会影响增量训练的效果,比如,学习率大小的选择等。另外,新的数据积累到何种规模可以进行增量训练也是实践中需要解决问题。一般来说,增量训练使用的数据量越大,训练的效果越稳定。但是,这并不是说数据量少就不可以进行增量训练,而是如果数据量过少时,需要考虑训练代价和效果之间的平衡。而且,过于频繁的增量训练也会带来更多的灾难性遗忘的风险,因此合理进行增量训练也是应用中需要实践的。
\parinterval 主要注意的是,理想状态下,系统使用者会希望系统看到少量句子就可以很好地解决一类翻译问题,即:进行真正的小样本学习。但是,现实的情况是,现在的机器翻译系统还无法很好的做到“举一反三”。增量训练也需要专业人士完成才能得到相对较好的效果。
\parinterval 另一个实际的问题是,当应用场景没有双语句对时是否可以优化系统?这个问题在{\chaptersixteen}的领域适应部分进行了一些讨论。一般来说,如果目标任务没有双语数据,仍然可以使用单语数据进行优化。常用的方法有数据增强、基于语言模型的方法等。具体方法可以参考{\chaptersixteen}的内容。
%----------------------------------------------------------------------------------------
% NEW SECTION
%----------------------------------------------------------------------------------------
\section{交互式机器翻译}
%----------------------------------------------------------------------------------------
% NEW SECTION
%----------------------------------------------------------------------------------------
\section{翻译结果可干预性}
%----------------------------------------------------------------------------------------
% NEW SECTION
%----------------------------------------------------------------------------------------
\section{小设备机器翻译}
\parinterval 在机器翻译研究中,一般会假设计算资源是充足的。但是,在很多应用场景中,机器翻译使用的计算资源非常有限,比如,一些离线设备上没有GPU处理器,而且CPU的处理能力也很弱,甚至内存也非常有限。这时,让模型变得更小、系统变得更快就成为了一个重要的需求。
\parinterval 本书中已经讨论了大量的技术方法,可用于小设备上的机器翻译,例如:
\begin{itemize}
\vspace{0.5em}
\item 知识蒸馏({\chapterthirteen})。这种方法可以有效地把翻译能力从大模型迁移到小模型。
\vspace{0.5em}
\item 低精度存储及计算({\chapterfourteen})。可以使用量化的方式将模型压缩,同时整数型计算也非常适合在CPU等设备上执行。
\vspace{0.5em}
\item 轻量模型结构({\chapterfourteen}{\chapterfifteen})。对机器翻译模型的局部结构进行优化也是非常有效的手段,比如,使用更加轻量的卷积计算模块,或者使用深编码器-浅解码器等结构等。
\vspace{0.5em}
\item 面向设备的结构学习({\chapterfifteen})。可以把设备的存储及延时作为目标函数的一部分,自动搜索高效的翻译模型结构。
\vspace{0.5em}
\item 动态适应性模型(引用:王强emnlp findings,还有Adaptive neural networks for fast test-time prediction,Multi-scale dense networks for resource efficient image classification)。模型可以动态调整大小或者计算规模,以达到在不同设备上平衡延时和精度的目的。比如,可以根据延时的要求,动态生成合适深度的神经网络模型进行翻译。
\vspace{0.5em}
\end{itemize}
\parinterval 此外,机器翻译系统的工程实现方式也是十分重要的,例如,编译器的选择、底层线性代数库的选择等等。有时候,使用与运行设备相匹配的编译器\footnote{以神经机器翻译为例,张量计算部分大多使用C++等语言编写,因此编译器与设备的适配程度对程序的执行效率影响很大。},会带来明显的性能提升。如果希望追求更加极致的性能,甚至需要对一些热点模块进行修改。例如,在神经机器翻译中,矩阵乘法就是一个非常耗时的部分。但是这部分计算又与设备、矩阵的形状有很大关系。对于不同设备,根据不同的矩阵形状可以设计相应的矩阵乘法算法。不过,这部分工作对系统开发和硬件指令的使用水平要求较高。
\parinterval 另一个工程问题是,在很多系统中,机器翻译模块并不是单独执行,而是与其他的模块并发执行。这时,由于多个计算密集型任务存在竞争,处理器要进行更多的上下文切换,会造成程序变慢。比如,机器翻译和语音识别两个模块一起运行时{\footnote{在一些语音翻译场景中,由于采用了语音识别和翻译异步执行的方式,两个程序可能会并发。}},机器翻译的速度会有较明显的下降。对于这种情况,需要设计更好的调度机制。而且在一些同时具有CPU和GPU的设备上,可以考虑合理调度CPU和GPU的资源,增加两种设备可并行处理的内容,避免在某个处理器上的拥塞。
\parinterval 除了运行速度,模型过大也是限制其在小设备上运行的障碍。在模型体积上,神经机器翻译具有天然的优势。因此,在对模型规模有苛刻要求的场景中,神经机器翻译是不二的选择。通过量化、剪枝、参数共享等方式,还可以将模型压缩一个数量级以上。
%----------------------------------------------------------------------------------------
% NEW SECTION
%----------------------------------------------------------------------------------------
\section{机器翻译系统部署}
\parinterval 除了在一些离线设备上使用机器翻译,更多时候机器翻译系统会部署在运算能力较强的服务器上。特别是随着神经机器翻译的大规模应用,在GPU服务器上部署机器翻译系统已经成为了常态。另一方面,GPU服务器的成本较高,而且很多应用中需要同时部署多个语言方向的系统。这时如何充分利用设备以满足大规模的翻译需求就成为了不可回避的问题。有几个方向值得尝试:
\begin{itemize}
\vspace{0.5em}
\item 对于多语言翻译的场景,使用单模型多语言翻译系统是一种很好的选择({\chaptersixteen})。当多个语种的数据量有限、使用频度不高时,这种方法可以很有效地解决翻译需求中长尾部分。例如,一些线上机器翻译服务已经支持超过100种语言的翻译,其中大部分语言之间的翻译需求是相对低频的,因此使用同一个模型进行翻译可以大大节约部署和运维的成本。
\vspace{0.5em}
\item 使用基于中介语言的翻译也可以有效的解决多语言翻译问题({\chaptersixteen})。这种方法同时适合统计机器翻译和神经机器翻译,因此很早就使用在大规模机器翻译部署中。
\vspace{0.5em}
\item GPU部署中,由于GPU成本较高,因此可以考虑在单GPU设备上部署多套不同的系统。如果这些系统之间的并发不频繁,翻译延时不会有明显增加。这种多个模型共享一个设备的方法比较适合翻译请求相对低频但是翻译任务又很多样的情况。
\vspace{0.5em}
\item 机器翻译大规模GPU部署对显存的使用也很严格。由于GPU显存较为有限,因此模型运行的显存消耗也是需要考虑的。一般来说,除了模型压缩和结构优化之外({\chapterfourteen}{\chapterfifteen}),也需要对模型的显存分配和使用进行单独的优化。例如,使用显存池来缓解频繁申请和释放显存空间造成的延时。另外,也可以尽可能让同一个显存块保存生命期不重叠的数据,避免重复开辟新的存储空间。图XXX 展示了一个显存复用的示例。
\vspace{0.5em}
\item 在翻译请求高并发的场景中,使用批量翻译也是有效利用GPU设备的方式。不过,机器翻译是一个处理不定长序列的任务,输入的句子长度差异较大。而且,由于译文长度无法预知,进一步增加了不同长度的句子所消耗计算资源的不确定性。这时,可以让长度相近的句子在一个批次里处理,减小由于句子长度不统一造成的补全过多、设备利用率低的问题。例如,可以按输入句子长度范围分组,如图XXX。 也可以设计更加细致的方法对句子进行分组,以最大化批量翻译中设备的利用率({\color{red} 参考文献:TurboTransformers: An Efficient GPU Serving System For Transformer Models})。
\vspace{0.5em}
\end{itemize}
\parinterval 除了上述问题,如何对多设备环境下进行负载均衡、容灾处理等都是大规模机器翻译系统部署中需要考虑的。有时候,甚至统计机器翻译系统也可以与神经机器翻译系统混合使用。由于统计机器翻译系统对GPU设备的要求较低,纯CPU部署的方案也相对成熟。因此,可以作为GPU机器翻译服务的灾备。此外,在有些任务,特别是低资源翻译任务上,统计机器翻译仍然具有优势。
%----------------------------------------------------------------------------------------
% NEW SECTION
%----------------------------------------------------------------------------------------
\section{机器翻译的应用场景}
%---------------------------------------------------------------------------------------- %----------------------------------------------------------------------------------------
% NEW SECTION % NEW SECTION
%---------------------------------------------------------------------------------------- %----------------------------------------------------------------------------------------
\section{} \section{拓展思考}
...@@ -8821,6 +8821,252 @@ author = {Zhuang Liu and ...@@ -8821,6 +8821,252 @@ author = {Zhuang Liu and
year = {2020} year = {2020}
} }
@article{DBLP:journals/corr/abs-1806-01261,
author = {Peter W. Battaglia and
Jessica B. Hamrick and
Victor Bapst and
Alvaro Sanchez-Gonzalez and
Vin{\'{\i}}cius Flores Zambaldi and
Mateusz Malinowski and
Andrea Tacchetti and
David Raposo and
Adam Santoro and
Ryan Faulkner and
{\c{C}}aglar G{\"{u}}l{\c{c}}ehre and
H. Francis Song and
Andrew J. Ballard and
Justin Gilmer and
George E. Dahl and
Ashish Vaswani and
Kelsey R. Allen and
Charles Nash and
Victoria Langston and
Chris Dyer and
Nicolas Heess and
Daan Wierstra and
Pushmeet Kohli and
Matthew Botvinick and
Oriol Vinyals and
Yujia Li and
Razvan Pascanu},
title = {Relational inductive biases, deep learning, and graph networks},
journal = {CoRR},
volume = {abs/1806.01261},
year = {2018}
}
@inproceedings{Shaw2018SelfAttentionWR,
author = {Peter Shaw and
Jakob Uszkoreit and
Ashish Vaswani},
title = {Self-Attention with Relative Position Representations},
publisher = {Annual Conference of the North American Chapter of the Association for Computational Linguistics},
pages = {464--468},
year = {2018},
}
@article{Dai2019TransformerXLAL,
author = {Zihang Dai and
Zhilin Yang and
Yiming Yang and
Jaime G. Carbonell and
Quoc V. Le and
Ruslan Salakhutdinov},
title = {Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context},
journal = {Annual Meeting of the Association for Computational Linguistics},
pages = {2978--2988},
year = {2019}
}
@inproceedings{vaswani2017attention,
title={Attention is All You Need},
author={Ashish {Vaswani} and Noam {Shazeer} and Niki {Parmar} and Jakob {Uszkoreit} and Llion {Jones} and Aidan N. {Gomez} and Lukasz {Kaiser} and Illia {Polosukhin}},
publisher={International Conference on Neural Information Processing},
pages={5998--6008},
year={2017}
}
@inproceedings{DBLP:conf/acl/LiXTZZZ17,
author = {Junhui Li and
Deyi Xiong and
Zhaopeng Tu and
Muhua Zhu and
Min Zhang and
Guodong Zhou},
title = {Modeling Source Syntax for Neural Machine Translation},
pages = {688--697},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2017}
}
@inproceedings{DBLP:conf/acl/EriguchiHT16,
author = {Akiko Eriguchi and
Kazuma Hashimoto and
Yoshimasa Tsuruoka},
title = {Tree-to-Sequence Attentional Neural Machine Translation},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2016}
}
@inproceedings{Yang2017TowardsBH,
author = {Baosong Yang and
Derek F. Wong and
Tong Xiao and
Lidia S. Chao and
Jingbo Zhu},
title = {Towards Bidirectional Hierarchical Representations for Attention-based
Neural Machine Translation},
publisher = {Conference on Empirical Methods in Natural Language Processing},
pages = {1432--1441},
year = {2017}
}
@inproceedings{DBLP:conf/acl/ChenHCC17,
author = {Huadong Chen and
Shujian Huang and
David Chiang and
Jiajun Chen},
title = {Improved Neural Machine Translation with a Syntax-Aware Encoder and
Decoder},
pages = {1936--1945},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2017}
}
@inproceedings{TuModeling,
author = {Zhaopeng Tu and
Zhengdong Lu and
Yang Liu and
Xiaohua Liu and
Hang Li},
title = {Modeling Coverage for Neural Machine Translation},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2016}
}
@inproceedings{DBLP:conf/wmt/SennrichH16,
author = {Rico Sennrich and
Barry Haddow},
title = {Linguistic Input Features Improve Neural Machine Translation},
pages = {83--91},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2016}
}
@inproceedings{DBLP:conf/emnlp/ShiPK16,
author = {Xing Shi and
Inkit Padhi and
Kevin Knight},
title = {Does String-Based Neural {MT} Learn Source Syntax?},
pages = {1526--1534},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2016}
}
@inproceedings{DBLP:conf/acl/BugliarelloO20,
author = {Emanuele Bugliarello and
Naoaki Okazaki},
title = {Enhancing Machine Translation with Dependency-Aware Self-Attention},
pages = {1618--1627},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2020}
}
@article{Aharoni2017TowardsSN,
title={Towards String-To-Tree Neural Machine Translation},
author={Roee Aharoni and
Yoav Goldberg},
journal={Annual Meeting of the Association for Computational Linguistics},
year={2017}
}
@inproceedings{DBLP:conf/iclr/Alvarez-MelisJ17,
author = {David Alvarez-Melis and
Tommi S. Jaakkola},
title = {Tree-structured decoding with doubly-recurrent neural networks},
publisher = {International Conference on Learning Representations},
year = {2017}
}
@inproceedings{DBLP:conf/naacl/DyerKBS16,
author = {Chris Dyer and
Adhiguna Kuncoro and
Miguel Ballesteros and
Noah A. Smith},
title = {Recurrent Neural Network Grammars},
pages = {199--209},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2016}
}
@book{aho1972theory,
author = {Aho, Alfred V and
Ullman, Jeffrey D},
title = {The theory of parsing, translation, and compiling},
publisher = {Prentice-Hall Englewood Cliffs, NJ},
year = {1973},
}
@inproceedings{DBLP:journals/corr/LuongLSVK15,
author = {Minh-Thang Luong and
Quoc V. Le and
Ilya Sutskever and
Oriol Vinyals and
Lukasz Kaiser},
title = {Multi-task Sequence to Sequence Learning},
publisher = {International Conference on Learning Representations},
year = {2016}
}
@inproceedings{DBLP:conf/wmt/NadejdeRSDJKB17,
author = {Maria Nadejde and
Siva Reddy and
Rico Sennrich and
Tomasz Dwojak and
Marcin Junczys-Dowmunt and
Philipp Koehn and
Alexandra Birch},
title = {Predicting Target Language {CCG} Supertags Improves Neural Machine
Translation},
pages = {68--79},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2017}
}
@inproceedings{DBLP:conf/acl/WuZYLZ17,
author = {Shuangzhi Wu and
Dongdong Zhang and
Nan Yang and
Mu Li and
Ming Zhou},
title = {Sequence-to-Dependency Neural Machine Translation},
pages = {698--707},
publisher = {Annual Meeting of the Association for Computational Linguistics},
year = {2017}
}
@inproceedings{DBLP:journals/corr/abs-1808-09374,
author = {Xinyi Wang and
Hieu Pham and
Pengcheng Yin and
Graham Neubig},
title = {A Tree-based Decoder for Neural Machine Translation},
publisher = {Conference on Empirical Methods in Natural Language Processing},
pages = {4772--4777},
year = {2018}
}
@inproceedings{Tong2016Syntactic,
author = {Tong Xiao and
Jingbo Zhu and
Chunliang Zhang and
Tongran Liu},
title = {Syntactic Skeleton-Based Translation},
pages = {2856--2862},
publisher = {AAAI Conference on Artificial Intelligence},
year = {2016},
}
%%%%% chapter 15------------------------------------------------------ %%%%% chapter 15------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论