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
621f1eeb
Commit
621f1eeb
authored
Dec 19, 2020
by
zengxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
12
parent
4955d974
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
5 行增加
和
5 行删除
+5
-5
Chapter12/chapter12.tex
+5
-5
没有找到文件。
Chapter12/chapter12.tex
查看文件 @
621f1eeb
...
...
@@ -281,7 +281,7 @@
\parinterval
在得到
$
\mathbi
{
Q
}$
,
$
\mathbi
{
K
}$
和
$
\mathbi
{
V
}$
后,便可以进行注意力机制的运算,这个过程可以被形式化为公式
\eqref
{
eq:12-9
}
:
\begin{eqnarray}
\textrm
{
Attention
}
(
\mathbi
{
Q
}
,
\mathbi
{
K
}
,
\mathbi
{
V
}
)
=
\textrm
{
Softmax
}
\textrm
{
Attention
}
(
\mathbi
{
Q
}
,
\mathbi
{
K
}
,
\mathbi
{
V
}
)
&
=
&
\textrm
{
Softmax
}
(
\frac
{
\mathbi
{
Q
}
\mathbi
{
K
}^{
\textrm
{
T
}}}
{
\sqrt
{
d
_
k
}}
+
\mathbi
{
Mask
}
)
\mathbi
{
V
}
\label
{
eq:12-9
}
\end{eqnarray}
...
...
@@ -417,13 +417,13 @@
\parinterval
在Transformer的训练过程中,由于引入了残差操作,将前面所有层的输出加到一起,如公式
\eqref
{
eq:12-12
}
所示:
\begin{eqnarray}
%x_{l+1} = x_l + F (x_l)
\mathbi
{
x
}^{
l+1
}
=
F (
\mathbi
{
x
}^
l) +
\mathbi
{
x
}^
l
\mathbi
{
x
}^{
l+1
}
&
=
&
F (
\mathbi
{
x
}^
l) +
\mathbi
{
x
}^
l
\label
{
eq:12-12
}
\end{eqnarray}
\noindent
其中
$
\mathbi
{
x
}^
l
$
表示第
$
l
$
层网络的输入向量,
$
F
(
\mathbi
{
x
}^
l
)
$
是子层运算,这样会导致不同层(或子层)的结果之间的差异性很大,造成训练过程不稳定、训练时间较长。为了避免这种情况,在每层中加入了层标准化操作
\upcite
{
Ba2016LayerN
}
。图
\ref
{
fig:12-14
}
中的红色方框展示了Transformer中残差和层标准化的位置。层标准化的计算如公式
\eqref
{
eq:12-13
}
所示:
\begin{eqnarray}
\textrm
{
LN
}
(
\mathbi
{
x
}
)
=
g
\cdot
\frac
{
\mathbi
{
x
}
-
\mu
}
{
\sigma
}
+ b
\textrm
{
LN
}
(
\mathbi
{
x
}
)
&
=
&
g
\cdot
\frac
{
\mathbi
{
x
}
-
\mu
}
{
\sigma
}
+ b
\label
{
eq:12-13
}
\end{eqnarray}
...
...
@@ -459,7 +459,7 @@
\parinterval
Transformer使用了全连接网络。全连接网络的作用主要体现在将经过注意力操作之后的表示映射到新的空间中,新的空间会有利于接下来的非线性变换等操作。实验证明,去掉全连接网络会对模型的性能造成很大影响。Transformer的全连接前馈神经网络包含两次线性变换和一次非线性变换(ReLU激活函数:ReLU
$
(
\mathbi
{
x
}
)=
\textrm
{
max
}
(
0
,
\mathbi
{
x
}
)
$
),每层的前馈神经网络参数不共享,具体计算如公式
\eqref
{
eq:12-14
}
:
\begin{eqnarray}
\textrm
{
FFN
}
(
\mathbi
{
x
}
)
=
\textrm
{
max
}
(0,
\mathbi
{
x
}
\mathbi
{
W
}_
1 +
\mathbi
{
b
}_
1)
\mathbi
{
W
}_
2 +
\mathbi
{
b
}_
2
\textrm
{
FFN
}
(
\mathbi
{
x
}
)
&
=
&
\textrm
{
max
}
(0,
\mathbi
{
x
}
\mathbi
{
W
}_
1 +
\mathbi
{
b
}_
1)
\mathbi
{
W
}_
2 +
\mathbi
{
b
}_
2
\label
{
eq:12-14
}
\end{eqnarray}
...
...
@@ -489,7 +489,7 @@
\item
Transformer使用Adam优化器优化参数,并设置
$
\beta
_
1
=
0
.
9
$
,
$
\beta
_
2
=
0
.
98
$
,
$
\epsilon
=
10
^{
-
9
}$
。
\item
Transformer在学习率中同样应用了学习率
{
\small\bfnew
{
预热
}}
\index
{
预热
}
(Warmup)
\index
{
Warmup
}
策略,其计算如公式
\eqref
{
eq:12-15
}
所示:
\begin{eqnarray}
lrate
=
d
_{
\textrm
{
model
}}^{
-0.5
}
\cdot
\textrm
{
min
}
(
\textrm
{
step
}^{
-0.5
}
,
\textrm
{
step
}
\cdot
\textrm
{
warmup
\_
steps
}^{
-1.5
}
)
lrate
&
=
&
d
_{
\textrm
{
model
}}^{
-0.5
}
\cdot
\textrm
{
min
}
(
\textrm
{
step
}^{
-0.5
}
,
\textrm
{
step
}
\cdot
\textrm
{
warmup
\_
steps
}^{
-1.5
}
)
\label
{
eq:12-15
}
\end{eqnarray}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论