Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
M
mtbookv2
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
mtbookv2
Commits
650f11da
Commit
650f11da
authored
Sep 14, 2020
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wording (sec 12)
parent
fa92b495
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
13 行增加
和
17 行删除
+13
-17
Chapter12/Figures/figure-example-of-self-attention-mechanism-calculation.tex
+6
-6
Chapter12/chapter12.tex
+5
-8
mt-book-xelatex.tex
+2
-3
没有找到文件。
Chapter12/Figures/figure-example-of-self-attention-mechanism-calculation.tex
查看文件 @
650f11da
...
...
@@ -7,13 +7,13 @@
\node
[rnode,anchor=south west,fill=green!20!white] (key11) at (0,0)
{
\scriptsize
{$
\vectorn
{
\emph
{
h
}}
(
\textrm
{
“你”
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key12) at ([xshift=0.8em]key11.south east)
{
\scriptsize
{$
\vectorn
{
\emph
{
h
}}
(
\textrm
{
“什么”
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key13) at ([xshift=0.8em]key12.south east)
{
\scriptsize
{$
\vectorn
{
\emph
{
h
}}
(
\textrm
{
“也”
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key14) at ([xshift=0.8em]key13.south east)
{
\scriptsize
{$
\vectorn
{
\emph
{
h
}}
(
\textrm
{
“没”
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key15) at ([xshift=0.8em]key14.south east)
{
\scriptsize
{$
\vectorn
{
\emph
{
h
}}
(
\textrm
{
“学”
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key11) at (0,0)
{
\scriptsize
{$
h
(
\textrm
{
你
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key12) at ([xshift=0.8em]key11.south east)
{
\scriptsize
{$
h
(
\textrm
{
什么
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key13) at ([xshift=0.8em]key12.south east)
{
\scriptsize
{$
h
(
\textrm
{
也
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key14) at ([xshift=0.8em]key13.south east)
{
\scriptsize
{$
h
(
\textrm
{
没
}
)
$}}
;
\node
[rnode,anchor=south west,fill=green!20!white] (key15) at ([xshift=0.8em]key14.south east)
{
\scriptsize
{$
h
(
\textrm
{
学
}
)
$}}
;
\node
[rnode,anchor=east] (query1) at ([xshift=-1em]key11.west)
{
\scriptsize
{$
\vectorn
{
\emph
{
h
}}
(
\textrm
{
“你”
}
)
$}}
;
\node
[rnode,anchor=east] (query1) at ([xshift=-1em]key11.west)
{
\scriptsize
{$
h
(
\textrm
{
你
}
)
$}}
;
\draw
[->] ([yshift=1pt,xshift=4pt]query1.north) .. controls +(90:0.6em) and +(90:0.6em) .. ([yshift=1pt]key11.north);
\draw
[->] ([yshift=1pt,xshift=0pt]query1.north) .. controls +(90:1.0em) and +(90:1.0em) .. ([yshift=1pt]key12.north);
...
...
Chapter12/chapter12.tex
查看文件 @
650f11da
...
...
@@ -69,19 +69,16 @@
\end{figure}
%----------------------------------------------
\parinterval
举个例子,如图
\ref
{
fig:12-38
}
所示,一个汉语句子包含5个词。这里,用
$
\vectorn
{
\emph
{
h
}}$
(“你”)表示“你”当前的表示结果。如果把“你”看作目标,这时
$
\mathrm
{
query
}$
就是
$
\vectorn
{
\emph
{
h
}}$
(“你”),
$
\mathrm
{
key
}$
和
$
\mathrm
{
value
}$
是图中所有位置的表示,即:
{$
\vectorn
{
\emph
{
h
}}$
(“你”)、
$
\vectorn
{
\emph
{
h
}}$
(“什么”)、
$
\vectorn
{
\emph
{
h
}}$
(“也”)、
$
\vectorn
{
\emph
{
h
}}$
(“没”)、
$
\vectorn
{
\emph
{
h
}}$
(“ 学”)
}
。在自注意力模型中,首先计算
$
\mathrm
{
query
}$
和
$
\mathrm
{
key
}$
的相关度,这里用
$
\alpha
_
i
$
表示
$
\vectorn
{
\emph
{
h
}}$
(“你”)和位置
$
i
$
的表示之间的相关性。然后,把
$
\alpha
_
i
$
作为权重,对不同位置上的
$
\mathrm
{
value
}$
进行加权求和。最终,得到新的表示结果
$
\tilde
{
\vectorn
{
\emph
{
h
}}
}$
(“你” ):
\parinterval
举个例子,如图
\ref
{
fig:12-38
}
所示,一个汉语句子包含5个词。这里,用
$
h
$
(“你”)表示“你”当前的表示结果,其中
$
h
(
\cdot
)
$
是一个函数,用于返回输入单词所在位置对应的表示结果(向量)。如果把“你”看作目标,这时
$
\mathrm
{
query
}$
就是
$
h
$
(你),
$
\mathrm
{
key
}$
和
$
\mathrm
{
value
}$
是图中所有位置的表示,即:
{$
h
$
(你)、
$
h
$
(什么)、
$
h
$
(也)、
$
h
$
(没)、
$
h
$
(学)
}
。在自注意力模型中,首先计算
$
\mathrm
{
query
}$
和
$
\mathrm
{
key
}$
的相关度,这里用
$
\alpha
_
i
$
表示
$
h
$
(你)和位置
$
i
$
的表示之间的相关性。然后,把
$
\alpha
_
i
$
作为权重,对不同位置上的
$
\mathrm
{
value
}$
进行加权求和。最终,得到新的表示结果
$
\tilde
{
h
}$
(“你” ):
\begin{eqnarray}
\tilde
{
\vectorn
{
\emph
{
h
}}}
(
\textrm
{
“你”
}
) =
\alpha
_
1
{
\vectorn
{
\emph
{
h
}}}
(
\textrm
{
“你”
}
)
+
\alpha
_
2
{
\vectorn
{
\emph
{
h
}}}
(
\textrm
{
“什么 ”
}
)
+
\alpha
_
3
{
\vectorn
{
\emph
{
h
}}}
(
\textrm
{
“也”
}
)
+
\alpha
_
4
{
\vectorn
{
\emph
{
h
}}}
(
\textrm
{
“没”
}
)
+
\alpha
_
5
{
\vectorn
{
\emph
{
h
}}}
(
\textrm
{
“学”
}
)
\nonumber
\\
\tilde
{
h
}
(
\textrm
{
你
}
)
&
=
&
\alpha
_
1
{
h
}
(
\textrm
{
你
}
) +
\alpha
_
2
{
h
}
(
\textrm
{
什么
}
) +
\alpha
_
3
{
h
}
(
\textrm
{
也
}
) +
\nonumber
\\
&
&
\alpha
_
4
{
h
}
(
\textrm
{
没
}
) +
\alpha
_
5
{
h
}
(
\textrm
{
学
}
)
\label
{
eq:12-42
}
\end{eqnarray}
\parinterval
同理,也可以用同样的方法处理这个句子中的其他单词。可以看出,在注意力机制中,并不是使用类似于循环神经网络的记忆能力去访问历史信息。序列中所有单词之间的信息都是通过同一种操作(
$
\mathrm
{
query
}$
和
$
\mathrm
{
key
}$
的相关度)进行处理。这样,表示结果
$
\tilde
{
\vectorn
{
\emph
{
h
}}}
(
\textrm
{
“你”
}
)
$
在包含“你”这个单词的信息的同时,也包含了序列中其他词的信息。也就是,序列中每一个位置的表示结果中,都包含了其他位置的信息。从这个角度说,
$
\tilde
{
\vectorn
{
\emph
{
h
}}}
(
\textrm
{
“你”
}
)
$
已经不再是单词“你”自身的表示结果,而是一种在单词“你”的位置上的全局信息的表示。
\parinterval
同理,也可以用同样的方法处理这个句子中的其他单词。可以看出,在注意力机制中,并不是使用类似于循环神经网络的记忆能力去访问历史信息。序列中所有单词之间的信息都是通过同一种操作(
$
\mathrm
{
query
}$
和
$
\mathrm
{
key
}$
的相关度)进行处理。这样,表示结果
$
\tilde
{
h
}
(
\textrm
{
你
}
)
$
在包含“你”这个单词的信息的同时,也包含了序列中其他词的信息。也就是,序列中每一个位置的表示结果中,都包含了其他位置的信息。从这个角度说,
$
\tilde
{
h
}
(
\textrm
{
你
}
)
$
已经不再是单词“你”自身的表示结果,而是一种在单词“你”的位置上的全局信息的表示。
\parinterval
通常,也把生成
\{
$
\tilde
{
\vectorn
{
\emph
{
h
}}
}
(
\vectorn
{
\emph
{
w
}}_
i
)
$
\}
的过程称为
{
\small\sffamily\bfseries
{
特征提取
}}
\index
{
特征提取
}
,而实现这个过程的模型被称为特征提取器。循环神经网络、自注意力模型都是典型的特征提取器。特征提取是神经机器翻译系统的关键步骤,在随后的内容中可以看到自注意力模型是一个非常适合机器翻译任务的特征提取器。
\parinterval
通常,也把生成
\{
$
\tilde
{
h
}
(
\vectorn
{
\emph
{
w
}}_
i
)
$
\}
的过程称为
{
\small\sffamily\bfseries
{
特征提取
}}
\index
{
特征提取
}
,而实现这个过程的模型被称为特征提取器。循环神经网络、自注意力模型都是典型的特征提取器。特征提取是神经机器翻译系统的关键步骤,在随后的内容中可以看到自注意力模型是一个非常适合机器翻译任务的特征提取器。
%----------------------------------------------------------------------------------------
% NEW SECTION
...
...
mt-book-xelatex.tex
查看文件 @
650f11da
...
...
@@ -139,9 +139,8 @@
%\include{Chapter6/chapter6}
%\include{Chapter7/chapter7}
%\include{Chapter8/chapter8}
\include
{
Chapter9/chapter9
}
%\include{Chapter10/chapter10}
%\include{Chapter9/chapter9}
\include
{
Chapter10/chapter10
}
%\include{Chapter11/chapter11}
%\include{Chapter12/chapter12}
%\include{Chapter13/chapter13}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论