%---------------------------------------------------------------------------------------- % CHAPTER 3 %---------------------------------------------------------------------------------------- \renewcommand\figurename{图}%将figure改为图 \renewcommand\tablename{表}%将figure改为图 \chapterimage{chapter_head_1.pdf} % Chapter heading image \chapter{基于词的翻译模型} \hspace{2em}统计机器翻译和神经机器翻译在当前具有统治性意义。这两种方法各有优缺点,并没有那种方法具有绝对的优势。但从研究的角度来看,神经机器翻译整体上更具有前沿性。本章主要介绍了统计机器翻译的开山之作—IBM模型,它主要讲了怎么使用词汇对机器翻译进行建模。IBM模型由Peter E. Brown等人在1993年提出,并详细阐述于论文—《The Mathematics of Statistical Machine Translation: Parameter Estimation》。这篇文章的视野和对问题的定义远超当时人所能看到的东西,其衍生出来的一系列方法和新的问题还被后人花费将近10年的时间来进行研究与讨论。 \section{什么是基于词的翻译模型}\index{Chapter3.1}%Index的作用,目前不清晰 \hspace{2em}在机器翻译中,我们希望得到一个源语句到目标语译文的翻译。但机器并不知道如何翻译。因此在做机器翻译的过程中,最初面临的一个问题是:如何对翻译进行建模?从计算机的角度看,建模的目的就是把抽象的问题转换为可计算的问题。所以机器翻译的一个核心问题是:如何将翻译转换为一个可计算的模型或过程。 \noindent\hspace{2em}基于单词的统计机器翻译模型又是如何描述翻译的呢?IBM模型提出了一个观点:在翻译源语句时,通常是把每个源语句的单词翻译成对应的目标语单词,然后调整这些单词的顺序,最后得到翻译结果。尽管在人看来基于单词的对应进行翻译是很自然的事,但是机器并不一定。 \noindent\hspace{2em}举个例子说明如何基于单词的对应进行翻译。如图 \ref{figureC3.1}所示,表示的是汉译英的例子。其中源语句是“我 对 你 感到 满意”。首先我们把源语句的单词“我”、“对”、“\\你”、“感到”和“满意”分别翻译为“I”、“with”、“you”、“am”和“satisfied”,然后调整单词的顺序,比如“am”放在译文的第2个位置,“you”应该放在最后的位置等,最后得到译文“I am satisfied with you”。 %空一行用来段落换行,noindent取消首行缩进,hspace{}指定缩进距离,1em等于两个英文字符|一个汉字 %---------------------------------------------- % 图3.1 \definecolor{ublue}{rgb}{0.152,0.250,0.545} \begin{figure}[htp] \centering \definecolor{ublue}{rgb}{0.152,0.250,0.545} \begin{tikzpicture} \begin{scope} \node [anchor=west] (s1) at (0,0) {我}; \node [anchor=west] (s2) at ([xshift=0.5em]s1.east) {对}; \node [anchor=west] (s3) at ([xshift=0.5em]s2.east) {你}; \node [anchor=west] (s4) at ([xshift=0.5em]s3.east) {感到}; \node [anchor=west] (s5) at ([xshift=0.5em]s4.east) {满意}; \end{scope} \begin{scope}[yshift=-3em] \node [anchor=west] (t1) at (0.35em,0) {I}; \node [anchor=west] (t2) at ([xshift=0.3em,yshift=-0.1em]t1.east) {am}; \node [anchor=west] (t3) at ([xshift=0.3em,yshift=0.1em]t2.east) {satisfied}; \node [anchor=west] (t4) at ([xshift=0.3em]t3.east) {with}; \node [anchor=west] (t5) at ([xshift=0.3em,yshift=-0.2em]t4.east) {you}; \end{scope} { \draw [-,thick,ublue,dashed] (s1.south) -- (t1.north); \draw [-,thick,ublue,dashed] (s4.south) -- ([yshift=0.3em]t2.north); \draw [-,thick,ublue,dashed] (s2.south) ..controls +(south:1em) and +(north:1em).. (t4.north); \draw [-,thick,ublue,dashed] (s3.south) ..controls +(south:0.5em) and +(north:1.5em).. (t5.north); \draw [-,thick,ublue,dashed] (s5.south) -- (t3.north); } \end{tikzpicture} \caption{此处为图片的描述...例:基于词对应进行翻译.} \label{figureC3.1} \end{figure} %------------------------------------------- \noindent\hspace{2em}传统观点认为基于词的翻译过程包含如下三个步骤。如图 \ref{figureC3.2}所示。 \noindent\hspace{2em}第一、分析。将源语句或目标语句切分或者表示为能够处理的最小单元的过程。在基于词的翻译模型的最小处理单元就是单词。在这里也可以简单地将分析理解为分词。 \noindent\hspace{2em}第二、转换。把源语句中的每个单词都翻译成目标语单词。此处引用Figure \ref{figureC3.1}作为示例。 \noindent\hspace{2em}第三、生成。基于转换的结果,将目标语译文变成通顺且合乎语法的句子。 %---------------------------------------------- % 图3.2 \begin{figure}[htp] \centering \begin{tikzpicture} \definecolor{ugreen}{rgb}{0,0.5,0} \definecolor{ublue}{rgb}{0.152,0.250,0.545} \node [anchor=west,draw,thick,minimum width=6.7em,minimum height=0.8em] (sent) at (0,0) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,red] (s1) at ([yshift=-1.5em]sent.south west) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,ugreen] (s2) at ([xshift=0.4em]s1.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,orange] (s3) at ([xshift=0.4em]s2.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,ublue] (s4) at ([xshift=0.4em]s3.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,purple] (s5) at ([xshift=0.4em]s4.east) {}; { \node [anchor=west,draw,thick,circle,minimum size=0.3em,red,fill=red] (t1) at ([yshift=-2.0em]s1.west) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,ugreen,fill=ugreen] (t2) at ([xshift=0.4em]t1.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,orange,fill=orange] (t3) at ([xshift=0.4em]t2.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,ublue,fill=ublue] (t4) at ([xshift=0.4em]t3.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,purple,fill=purple] (t5) at ([xshift=0.4em]t4.east) {}; } { \node [anchor=west,draw,thick,circle,minimum size=0.3em,red,fill=red] (ft1) at ([yshift=-2.0em]t1.west) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,ublue,fill=ublue] (ft2) at ([xshift=0.4em]ft1.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,purple,fill=purple] (ft3) at ([xshift=0.4em]ft2.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,ugreen,fill=ugreen] (ft4) at ([xshift=0.4em]ft3.east) {}; \node [anchor=west,draw,thick,circle,minimum size=0.3em,orange,fill=orange] (ft5) at ([xshift=0.4em]ft4.east) {}; } \draw [->,thick,double] ([yshift=-0.1em]sent.south) -- ([yshift=-0.8em]sent.south); { \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); } { \draw [->,thick] ([yshift=-0.1em]t1.south) -- ([yshift=0.1em]ft1.north); \draw [->,thick] ([yshift=-0.1em]t2.south) -- ([yshift=0.1em]ft4.north); \draw [->,thick] ([yshift=-0.1em]t3.south) -- ([yshift=0.1em]ft5.north); \draw [->,thick] ([yshift=-0.1em]t4.south) -- ([yshift=0.1em]ft2.north); \draw [->,thick] ([yshift=-0.1em]t5.south) -- ([yshift=0.1em]ft3.north); } { \node [anchor=north west] (label1) at ([yshift=0.3em]sent.south east) {{\scriptsize \textbf{分析}}}; \node [anchor=north west] (label2) at ([yshift=-0.5em]label1.south west) {{\scriptsize \textbf{转换}}}; \node [anchor=north west] (label3) at ([yshift=-0.5em]label2.south west) {{\scriptsize \textbf{生成}}}; } \end{tikzpicture} \caption{此处为图片的描述...例:基于词的翻译过程.} \label{figureC3.2} \end{figure} %--------------------------- \noindent\hspace{2em}从现在的角度看,分析、转换和生成依然是非常深刻的一个观点。该过程蕴含于很多的任务,比如句法分析。即使对于神经机器翻译,从大的框架来说,依然在做分析、转换和生成,只不过有些过程隐含在神经网络的设计中。 \section{构建一个简易机器翻译系统}\index{Chapter3.2}%Index的作用,目前不清晰 \noindent\hspace{2em}本节首先对比人工翻译流程和机器翻译流程的异同点,从中我们可以归纳出构建机器翻译系统的两个主要流程:训练和解码。其次从单词翻译概率、句子级翻译模型和解码三个方面描述如何构建一个简易机器翻译系统。其中单词翻译概率和句子级翻译模型属于训练流程。 \subsection{机器翻译的思路}\index{Chapter3.2.1} \subsubsection{人工翻译流程}\index{Chapter3.2.1.1} \noindent\hspace{2em}当我们翻译一个句子时,首先会快速地分析出句子中词的构成,然后基于以往的知识,得到每个词的候选翻译,最后利用对单词的理解拼出来一个译文。这描述了人在翻译时的基本过程。尽管并不是严格的从心理学或者脑科学得出来的观点,但至少可以帮助我们理解人的翻译。 %---------------------------------------------- % 图3.3 \begin{figure}[htp] \centering \definecolor{ublue}{rgb}{0.152,0.250,0.545} \begin{tikzpicture} \begin{scope} \node [anchor=west] (s1) at (0,0) {\textbf{我}}; \node [anchor=west] (s2) at ([xshift=2em]s1.east) {\textbf{对}}; \node [anchor=west] (s3) at ([xshift=2em]s2.east) {\textbf{你}}; \node [anchor=west] (s4) at ([xshift=2em]s3.east) {\textbf{表示}}; \node [anchor=west] (s5) at ([xshift=2em]s4.east) {\textbf{满意}}; \node [anchor=south west] (sentlabel) at ([yshift=-0.5em]s1.north west) {\scriptsize{\textbf{\color{red}{待翻译句子(已经分词):}}}}; { \draw [->,very thick,ublue] (s1.south) -- ([yshift=-0.7em]s1.south); \draw [->,very thick,ublue] (s2.south) -- ([yshift=-0.7em]s2.south); \draw [->,very thick,ublue] (s3.south) -- ([yshift=-0.7em]s3.south); \draw [->,very thick,ublue] (s4.south) -- ([yshift=-0.7em]s4.south); \draw [->,very thick,ublue] (s5.south) -- ([yshift=-0.7em]s5.south); {\small \node [anchor=north,inner sep=2pt,fill=red!20,minimum height=1.5em,minimum width=2.5em] (t11) at ([yshift=-1em]s1.south) {I}; \node [anchor=north,inner sep=2pt,fill=red!20,minimum height=1.5em,minimum width=2.5em] (t12) at ([yshift=-0.2em]t11.south) {me}; \node [anchor=north,inner sep=2pt,fill=red!20,minimum height=1.5em,minimum width=2.5em] (t13) at ([yshift=-0.2em]t12.south) {I'm}; \node [anchor=north west,inner sep=1pt,fill=black] (tl11) at (t11.north west) {\tiny{{\color{white} \textbf{1}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (tl12) at (t12.north west) {\tiny{{\color{white} \textbf{1}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (tl13) at (t13.north west) {\tiny{{\color{white} \textbf{1}}}}; \node [anchor=north,inner sep=2pt,fill=green!20,minimum height=1.5em,minimum width=2.5em] (t21) at ([yshift=-1em]s2.south) {to}; \node [anchor=north,inner sep=2pt,fill=green!20,minimum height=1.5em,minimum width=2.5em] (t22) at ([yshift=-0.2em]t21.south) {with}; \node [anchor=north,inner sep=2pt,fill=green!20,minimum height=1.5em,minimum width=2.5em] (t23) at ([yshift=-0.2em]t22.south) {for}; \node [anchor=north west,inner sep=1pt,fill=black] (tl21) at (t21.north west) {\tiny{{\color{white} \textbf{2}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (tl22) at (t22.north west) {\tiny{{\color{white} \textbf{2}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (tl23) at (t23.north west) {\tiny{{\color{white} \textbf{2}}}}; \node [anchor=north,inner sep=2pt,fill=blue!20,minimum height=1.5em,minimum width=2.5em] (t31) at ([yshift=-1em]s3.south) {you}; \node [anchor=north west,inner sep=1pt,fill=black] (tl31) at (t31.north west) {\tiny{{\color{white} \textbf{3}}}}; \node [anchor=north,inner sep=2pt,fill=orange!20,minimum height=1.5em,minimum width=3em] (t41) at ([yshift=-1em]s4.south) {$\phi$}; \node [anchor=north,inner sep=2pt,fill=orange!20,minimum height=1.5em,minimum width=3em] (t42) at ([yshift=-0.2em]t41.south) {show}; \node [anchor=north west,inner sep=1pt,fill=black] (tl41) at (t41.north west) {\tiny{{\color{white} \textbf{4}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (tl42) at (t42.north west) {\tiny{{\color{white} \textbf{4}}}}; \node [anchor=north,inner sep=2pt,fill=purple!20,minimum height=1.5em,minimum width=4.5em] (t51) at ([yshift=-1em]s5.south) {satisfy}; \node [anchor=north,inner sep=2pt,fill=purple!20,minimum height=1.5em,minimum width=4.5em] (t52) at ([yshift=-0.2em]t51.south) {satisfied}; \node [anchor=north,inner sep=2pt,fill=purple!20,minimum height=1.5em,minimum width=4.5em] (t53) at ([yshift=-0.2em]t52.south) {satisfies}; \node [anchor=north west,inner sep=1pt,fill=black] (tl51) at (t51.north west) {\tiny{{\color{white} \textbf{5}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (tl52) at (t52.north west) {\tiny{{\color{white} \textbf{5}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (tl53) at (t53.north west) {\tiny{{\color{white} \textbf{5}}}}; } } \end{scope} \begin{scope} {\small { \node [anchor=west,inner sep=2pt,fill=red!20,minimum height=1.5em,minimum width=2.5em] (ft11) at ([yshift=-1.2in]t11.west) {I'm}; \node [anchor=center,inner sep=2pt,fill=purple!20,minimum height=1.5em,minimum width=5em] (ft12) at ([xshift=5.0em]ft11.center) {satisfied}; \node [anchor=center,inner sep=2pt,fill=green!20,minimum height=1.5em,minimum width=2.5em] (ft13) at ([xshift=5.0em]ft12.center) {with}; \node [anchor=center,inner sep=2pt,fill=blue!20,minimum height=1.5em,minimum width=2.5em] (ft14) at ([xshift=4.0em]ft13.center) {you}; } { \node [anchor=north west,inner sep=1pt,fill=black] (ftl11) at (ft11.north west) {\tiny{{\color{white} \textbf{1}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (ftl12) at (ft12.north west) {\tiny{{\color{white} \textbf{5}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (ftl13) at (ft13.north west) {\tiny{{\color{white} \textbf{2}}}}; \node [anchor=north west,inner sep=1pt,fill=black] (ftl14) at (ft14.north west) {\tiny{{\color{white} \textbf{3}}}}; } { \draw [->,thick] ([yshift=-0.1em]t13.south) -- ([yshift=0.1em]ft11.north); \draw [->,thick] ([yshift=0.1em]t22.south east) ..controls +(280:3em) and +(north:3em).. ([yshift=0.1em]ft13.north); \draw [->,thick] ([yshift=-0.1em,xshift=0.2em]t31.south west) ..controls +(south:3em) and +(north:3em).. ([yshift=0.1em,xshift=0.2em]ft14.north west); \draw [->,thick] ([yshift=0.1em]t52.south west) ..controls +(250:4em) and +(north:4em).. ([yshift=0.1em]ft12.north); \node [anchor=east,inner sep=1pt] (nulltranslabel) at (t42.south west) {\scriptsize{\textbf{翻空}}}; \draw [->,thick] ([yshift=0.1em]t41.south west) ..controls +(250:1em) and +(north:1em).. (nulltranslabel.north); } } \end{scope} \begin{scope} { \node [anchor=north west] (label1) at (ft11.south west) {\small{选择最佳单词翻译,调整词序,得到完美的结果}}; } { \draw[decorate,thick,decoration={brace,amplitude=5pt,mirror}] ([yshift=8em,xshift=-0.5em]t13.south west) -- ([xshift=-0.5em]t13.south west) node [pos=0.5,left,xshift=-0.5em,yshift=0.5em] (label2) {\footnotesize{\textbf{学习到的}}}; \node [anchor=north west] (label2part2) at ([yshift=0.3em]label2.south west) {\footnotesize{\textbf{单词翻译}}}; } { \draw[decorate,thick,decoration={brace,amplitude=5pt,mirror}] ([yshift=-0.2em,xshift=-0.5em]t13.south west) -- ([yshift=-5em,xshift=-0.5em]t13.south west) node [pos=0.5,left,xshift=-0.5em,yshift=0.5em] (label3) {\footnotesize{\textbf{运用知识}}}; \node [anchor=north west] (label3part2) at ([yshift=0.3em]label3.south west) {\footnotesize{\textbf{生成译文}}}; } \end{scope} \end{tikzpicture} \caption{此处为图片的描述...例:人工翻译的过程} \label{figureC3.3} \end{figure} %--------------------------- \noindent\hspace{2em}如图\ref{figureC3.3}所示,表示的是人工翻译的过程。其中待翻译的句子是“我 对 你表示 满意”,它的一个可能译文是“I’m satisfied with you”。我们可以把上述过程总结为如下两个过程。 \noindent\hspace{2em}第一、学习单词的翻译。即获取待翻译句子的每个单词的候选翻译。比如“对”的可能译文有“to”、“with”和“for”等。对于人来说,可以通过阅读、背诵、做题或者老师教等途径获得,并在大脑中形成知识。这些知识就包含了源语词与目标语词对应关系。我们也把这个过程称之为学习过程。 \noindent\hspace{2em}第二、运用知识生成译文。当翻译一个课本上没有见过的句子时,我们可能会想到词之间的翻译关系、一些常见的单词搭配、主谓宾等语法知识等,比如“satisfied”后面常使用介词“with”来表示对人的满意等,并基于这些知识快速地对译文进行生成。 \subsubsection{机器翻译流程}\index{Chapter3.2.1.2} \noindent\hspace{2em}那么机器是如何完成翻译的呢?机器翻译可能没有人那么智能。因为一方面没有老师教给它一些非常好用的规则,使它能够快速得到译文。另一方面机器很笨,尽管它能知道每个单词的译文,但是不知道这些译文怎么拼装成句,甚至不知道哪些译文是对的。为了更加直观地理解机器在翻译时的困境,我们将其中需要解决的问题归纳如下。 \noindent\hspace{2em}问题一、如何将单词的译文拼装成句? \noindent\hspace{2em}问题二、如果可以将译文成句,那如何判断结果的好坏? \noindent\hspace{2em}对于问题一。机器最擅长的就是计算,它可以类似于走一条路径,尝试把译文拼装成句。如图3.4中蓝色和红色的线,表示的就是两条译文选择路径,区别在于“满意”和“对”的翻译候选是不一样的,蓝色线选择的是“satisfy”和“to”,而红色线是“satisfied”和“with”。换句话说,翻译就是一条译文选择路径,不同的译文对应不同的路径,并且词序也可以不同。机器可以利用它的计算能力找到很多这样的路径。 %-----------公式样例 \subsubsection{如何从一个双语平行数据中学习?}\index{Chapter3.2.3.2} \noindent\hspace{2em}在上一节的骰子游戏中,我们重复地掷骰子很多次,然后计算“1”到“6”各出现的次数,再除以掷的总次数,最后得到它们出现的近似概率。我们同样用类似的方式估计单词翻译概率。假设$x$表示任意源语单词,所有的目标语单词$y \in Y$都可能是它的译文。当给定一个互译的句对$(s,t)$,我们定义$\textrm{P}(x \leftrightarrow y; s, t)$表示在$(s,t)$中$x$和$y$互译的可能性或概率。其中$x$属于句子$s$中的词,而$y$属于$t$中的词,具体计算如公式\ref{eqC3.1}\\所示。 \begin{equation} \textrm{P}(x \leftrightarrow y; s,t) \equiv \textrm{P}(x,y;s,t) = \frac{c(x,y;s,t)}{\sum_{x',y'} c(x',y';s,t)} \label{eqC3.1} \end{equation} \noindent\hspace{2em}上式中分子$c(x,y;s,t)$表示$x$和$y$在句对$(s,t)$中共现的总次数,\cite{Aho-Ullman:1969:JCSS}分母$\sum_{x',y'} c(x',y';$ $s,t)$表示任意的$x'$和任意的$y'$在$(s,t)$中共现的总次数。\cite{book_key}为了更加清晰的理解如何计算$c(x,y;s,t)$,我们用图3.7描述的算法进行了说明。 \noindent\hspace{2em}这是一个table的样例,word里目前还没有使用表格,因此借用学长论文里的table,如表\ref{table-ner}所示 %---------------------- \begin{table}[htp] \small \begin{center} \begin{tabular}{l|l} \hline \bf Model & \bf F1 \\ \hline $best \ published$ \\ BiLSTM-CRF \cite{lample-etal-2016-neural} & 90.94 \\ BiLSTM-CRF+ELMo \cite{peters-etal-2018-deep} & 92.22 \\ BERT Base \cite{devlin2018bert} & 92.40 \\ BERT Large \cite{devlin2018bert} & 92.80 \\ BiLSTM-CRF+PCE \cite{Akbik2019PooledCE} & 93.18 \\ \hline Random RNNs w/o pre-trained LM & 90.64 \\ DARTS w/o pre-trained LM & 91.05 \\ I-DARTS ($n=2$) w/o pre-trained LM & 90.96 \\ I-DARTS ($n=1$) w/o pre-trained LM & 91.23 \\ \hline Random RNNs & 92.89 \\ DARTS & 93.13 \\ I-DARTS ($n=2$) & 93.14 \\ I-DARTS ($n=1$) & 93.47 \\ \hline \end{tabular} \end{center} \caption{\label{font-table} F1 scores on the CoNLL-2003 English NER test set. } \label{table-ner} \end{table}