Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
Toy-MT-Introduction
概览
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
单韦乔
Toy-MT-Introduction
Commits
1485b49e
Commit
1485b49e
authored
Jan 04, 2020
by
Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RNN input & output figures
parent
cbd21156
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
273 行增加
和
253 行删除
+273
-253
Section06-Neural-Machine-Translation/section06.tex
+273
-253
没有找到文件。
Section06-Neural-Machine-Translation/section06.tex
查看文件 @
1485b49e
...
@@ -1134,267 +1134,287 @@ NLP问题的隐含结构假设 & 无隐含结构假设,端到端学习 \\
...
@@ -1134,267 +1134,287 @@ NLP问题的隐含结构假设 & 无隐含结构假设,端到端学习 \\
%%%------------------------------------------------------------------------------------------------------------
%%%------------------------------------------------------------------------------------------------------------
%%% 词嵌入
%%% 词嵌入
\begin{frame}
{
模块1:词嵌入层
}
\begin{frame}
{
模块1:词嵌入层
}
\begin{itemize}
\item
词嵌入的作用是把离散化的单词表示转换为连续空间上的分布式表示
\begin{itemize}
\begin{itemize}
\item
把输入的词转换成唯一对应的词表大小的0-1向量
\item
词嵌入的作用是把离散化的单词表示转换为连续空间上的分布式表示
\item
根据0-1向量,从词嵌入矩阵中取出对应的词嵌入
$
e
()
$
\begin{itemize}
\item
取出的词嵌入
$
e
()
$
作为循环神经网络的输入
\item
<2-> 把输入的词转换成唯一对应的词表大小的0-1向量
\end{itemize}
\item
<3-> 根据0-1向量,从词嵌入矩阵中取出对应的词嵌入
$
e
()
$
\end{itemize}
\item
<4-> 取出的词嵌入
$
e
()
$
作为循环神经网络的输入
\vspace
{
-1em
}
\end{itemize}
%%% 图
\end{itemize}
\begin{center}
\vspace
{
-1em
}
\hspace*
{
-0.6cm
}
%%% 图
\begin{tikzpicture}
\begin{center}
\setlength
{
\base
}{
0.9cm
}
\hspace*
{
-0.6cm
}
\begin{tikzpicture}
\tikzstyle
{
rnnnode
}
= [rounded corners=1pt,minimum height=0.5
\base
,minimum width=1
\base
,draw,inner sep=0pt,outer sep=0pt]
\setlength
{
\base
}{
0.9cm
}
\tikzstyle
{
wordnode
}
= [font=
\tiny
]
\tikzstyle
{
rnnnode
}
= [rounded corners=1pt,minimum height=0.5
\base
,minimum width=1
\base
,draw,inner sep=0pt,outer sep=0pt]
% RNN translation model
\tikzstyle
{
wordnode
}
= [font=
\tiny
]
\begin{scope}
[local bounding box=RNNMT]
% RNN Encoder
% RNN translation model
\coordinate
(eemb0) at (0,0);
\begin{scope}
[local bounding box=RNNMT]
\foreach
\x
[count=
\y
from 0] in
{
1,2,...,3
}
% RNN Encoder
\node
[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=west]
(eemb
\x
) at ([xshift=0.4
\base
]eemb
\y
.east)
{
\tiny
{$
e
_
x
()
$}}
;
\coordinate
(eemb0) at (0,0);
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
[count=
\y
from 0] in
{
1,2,...,3
}
\node
[rnnnode,fill=blue!30!white,anchor=south]
(enc
\x
) at ([yshift=0.3
\base
]eemb
\x
.north)
{}
;
\node
[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=west]
(eemb
\x
) at ([xshift=0.4
\base
]eemb
\y
.east)
{
\tiny
{$
e
_
x
()
$}}
;
\node
[]
(enclabel1) at (enc1)
{
\tiny
{$
\textbf
{
h
}_{
m
-
2
}$}}
;
\foreach
\x
in
{
1,2,...,3
}
\node
[]
(enclabel2) at (enc2)
{
\tiny
{$
\textbf
{
h
}_{
m
-
1
}$}}
;
\node
[rnnnode,fill=blue!30!white,anchor=south]
(enc
\x
) at ([yshift=0.3
\base
]eemb
\x
.north)
{}
;
\node
[rnnnode,fill=purple!30!white]
(enclabel3) at (enc3)
{
\tiny
{$
\textbf
{
h
}_{
m
}$}}
;
\node
[]
(enclabel1) at (enc1)
{
\tiny
{$
\textbf
{
h
}_{
m
-
2
}$}}
;
\node
[wordnode,left=0.4\base of enc1]
(init1)
{$
\cdots
$}
;
\node
[]
(enclabel2) at (enc2)
{
\tiny
{$
\textbf
{
h
}_{
m
-
1
}$}}
;
\node
[wordnode,left=0.4\base of eemb1]
(init2)
{$
\cdots
$}
;
\node
[rnnnode,fill=purple!30!white]
(enclabel3) at (enc3)
{
\tiny
{$
\textbf
{
h
}_{
m
}$}}
;
\node
[wordnode,left=0.4\base of enc1]
(init1)
{$
\cdots
$}
;
\node
[wordnode,below=0pt of eemb1]
()
{
走
}
;
\node
[wordnode,left=0.4\base of eemb1]
(init2)
{$
\cdots
$}
;
\node
[wordnode,below=0pt of eemb2]
()
{
吗
}
;
\node
[wordnode,below=0pt of eemb3]
()
{$
\langle
$
eos
$
\rangle
$}
;
\node
[wordnode,below=0pt of eemb1]
()
{
走
}
;
\node
[wordnode,below=0pt of eemb2]
()
{
吗
}
;
% RNN Decoder
\node
[wordnode,below=0pt of eemb3]
()
{$
\langle
$
eos
$
\rangle
$}
;
\foreach
\x
in
{
1,2,...,3
}
\node
[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=south]
(demb
\x
) at ([yshift=
\base
]enc
\x
.north)
{
\tiny
{$
e
_
y
()
$}}
;
% RNN Decoder
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\node
[rnnnode,fill=blue!30!white,anchor=south]
(dec
\x
) at ([yshift=0.3
\base
]demb
\x
.north)
{{
\tiny
{$
\textbf
{
s
}_
\x
$}}}
;
\node
[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=south]
(demb
\x
) at ([yshift=
\base
]enc
\x
.north)
{
\tiny
{$
e
_
y
()
$}}
;
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\node
[rnnnode,minimum height=0.5\base,fill=red!30!white,anchor=south]
(softmax
\x
) at ([yshift=0.3
\base
]dec
\x
.north)
{
\tiny
{
Softmax
}}
;
\node
[rnnnode,fill=blue!30!white,anchor=south]
(dec
\x
) at ([yshift=0.3
\base
]demb
\x
.north)
{{
\tiny
{$
\textbf
{
s
}_
\x
$}}}
;
\node
[wordnode,right=0.4\base of demb3]
(end1)
{$
\cdots
$}
;
\foreach
\x
in
{
1,2,...,3
}
\node
[wordnode,right=0.4\base of dec3]
(end2)
{$
\cdots
$}
;
\node
[rnnnode,minimum height=0.5\base,fill=red!30!white,anchor=south]
(softmax
\x
) at ([yshift=0.3
\base
]dec
\x
.north)
{
\tiny
{
Softmax
}}
;
\node
[wordnode,right=0.4\base of softmax3]
(end3)
{$
\cdots
$}
;
\node
[wordnode,right=0.4\base of demb3]
(end1)
{$
\cdots
$}
;
\node
[wordnode,right=0.4\base of dec3]
(end2)
{$
\cdots
$}
;
% Decoder input words
\node
[wordnode,right=0.4\base of softmax3]
(end3)
{$
\cdots
$}
;
\node
[wordnode,below=0pt of demb1]
(decwordin)
{$
\langle
$
sos
$
\rangle
$}
;
\ExtractX
{$
(
demb
2
.south
)
$}
% Decoder input words
\ExtractY
{$
(
decwordin.base
)
$}
\node
[wordnode,below=0pt of demb1]
(decwordin)
{$
\langle
$
sos
$
\rangle
$}
;
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
Do
}
;
\ExtractX
{$
(
demb
2
.south
)
$}
\ExtractX
{$
(
demb
3
.south
)
$}
\ExtractY
{$
(
decwordin.base
)
$}
\ExtractY
{$
(
decwordin.base
)
$}
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
Do
}
;
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
you
}
;
\ExtractX
{$
(
demb
3
.south
)
$}
\ExtractY
{$
(
decwordin.base
)
$}
% Decoder output words
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
you
}
;
\node
[wordnode,above=0pt of softmax1]
(decwordout)
{
Do
}
;
\ExtractX
{$
(
softmax
2
.north
)
$}
% Decoder output words
\ExtractY
{$
(
decwordout.base
)
$}
\node
[wordnode,above=0pt of softmax1]
(decwordout)
{
Do
}
;
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
you
}
;
\ExtractX
{$
(
softmax
2
.north
)
$}
\ExtractX
{$
(
softmax
3
.north
)
$}
\ExtractY
{$
(
decwordout.base
)
$}
\ExtractY
{$
(
decwordout.base
)
$}
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
you
}
;
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
know
}
;
\ExtractX
{$
(
softmax
3
.north
)
$}
\ExtractY
{$
(
decwordout.base
)
$}
% Connections
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
know
}
;
\draw
[-latex']
(init1.east) to (enc1.west);
\draw
[-latex']
(dec3.east) to (end2.west);
% Connections
\foreach
\x
in
{
1,2,...,3
}
\draw
[-latex']
(init1.east) to (enc1.west);
\draw
[-latex']
(eemb
\x
) to (enc
\x
);
\draw
[-latex']
(dec3.east) to (end2.west);
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\draw
[-latex']
(demb
\x
) to (dec
\x
);
\draw
[-latex']
(eemb
\x
) to (enc
\x
);
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\draw
[-latex']
(dec
\x
.north) to (softmax
\x
.south);
\draw
[-latex']
(demb
\x
) to (dec
\x
);
\foreach
\x
[count=
\y
from 2] in
{
1,2
}
\foreach
\x
in
{
1,2,...,3
}
{
\draw
[-latex']
(dec
\x
.north) to (softmax
\x
.south);
\draw
[-latex']
(enc
\x
.east) to (enc
\y
.west);
\foreach
\x
[count=
\y
from 2] in
{
1,2
}
\draw
[-latex']
(dec
\x
.east) to (dec
\y
.west);
{
}
\draw
[-latex']
(enc
\x
.east) to (enc
\y
.west);
\draw
[-latex']
(dec
\x
.east) to (dec
\y
.west);
\coordinate
(bridge) at ([yshift=0.4
\base
]enc2.north west);
}
\draw
[-latex']
(enc3.north) .. controls +(north:0.3
\base
) and +(east:
\base
) .. (bridge) .. controls +(west:2.7
\base
) and +(west:0.3
\base
) .. (dec1.west);
\end{scope}
\coordinate
(bridge) at ([yshift=0.4
\base
]enc2.north west);
\draw
[-latex']
(enc3.north) .. controls +(north:0.3
\base
) and +(east:
\base
) .. (bridge) .. controls +(west:2.7
\base
) and +(west:0.3
\base
) .. (dec1.west);
\begin{scope}
\end{scope}
\coordinate
(start) at (5.8
\base
,0.3
\base
);
\node
[anchor=south west] (one) at (start)
{
\scriptsize
{$
\begin
{
bmatrix
}
0
\\
0
\\
0
\\
\vdots
\\
0
\\
{
\color
{
ugreen
}
1
}
\\
0
\\
0
\end
{
bmatrix
}$}}
;
\begin{scope}
\node
[anchor=north] (w) at ([yshift=3pt]one.south)
{
\scriptsize
{
\color
{
ugreen
}
you
}}
;
\coordinate
(start) at (5.8
\base
,0.3
\base
);
\node
[anchor=north west] (words) at ([xshift=10pt]one.north east)
{
\scriptsize
{$
\begin
{
matrix
}
\langle\textrm
{
eos
}
\rangle
\\
\langle\textrm
{
sos
}
\rangle
\\
\textrm
{
Do
}
\\
\vdots
\\
\textrm
{
know
}
\\
\textrm
{
you
}
\\
\textrm
{
?
}
\\
\textrm
{
have
}
\end
{
matrix
}$}}
;
\visible
<2->
{
\node
[anchor=north west] (mat) at ([xshift=-6pt]words.north east)
{
\scriptsize
{$
\node
[anchor=south west] (one) at (start)
{
\scriptsize
{$
\begin
{
bmatrix
}
0
\\
0
\\
0
\\
\vdots
\\
0
\\
{
\color
{
ugreen
}
1
}
\\
0
\\
0
\end
{
bmatrix
}$}}
;
\begin
{
bmatrix
}
}
.
1
&
-
4
&
\cdots
&
2
\\
\visible
<3->
{
5
&
2
&
\cdots
&
.
2
\\
\node
[draw=ugreen,fill=green!20!white,rounded corners=0.3em,minimum width=3.8cm,minimum height=0.9em,anchor=south west] (emb) at ([shift=
{
(1.25cm,0.8cm)
}
]start)
{}
;
2
&
.
1
&
\cdots
&
.
3
\\
}
\vdots
&
\vdots
&
\ddots
&
\vdots
\\
\node
[anchor=north] (w) at ([yshift=3pt]one.south)
{
\scriptsize
{
\color
{
ugreen
}
you
}}
;
0
&
.
8
&
\cdots
&
4
\\
\node
[anchor=north west] (words) at ([xshift=10pt]one.north east)
{
\scriptsize
{$
\begin
{
matrix
}
\langle\textrm
{
eos
}
\rangle
\\
\langle\textrm
{
sos
}
\rangle
\\
\textrm
{
Do
}
\\
\vdots
\\
\textrm
{
know
}
\\
\textrm
{
you
}
\\
\textrm
{
?
}
\\
\textrm
{
have
}
\end
{
matrix
}$}}
;
-
1
&
-
2
&
\cdots
&
-
3
\\
\node
[anchor=north west] (mat) at ([xshift=-6pt]words.north east)
{
\scriptsize
{$
.
7
&
.
5
&
\cdots
&
3
\\
\begin
{
bmatrix
}
-
2
&
.
3
&
\cdots
&
.
1
.
1
&
-
4
&
\cdots
&
2
\\
\end
{
bmatrix
}$
5
&
2
&
\cdots
&
.
2
\\
}}
;
2
&
.
1
&
\cdots
&
.
3
\\
\vdots
&
\vdots
&
\ddots
&
\vdots
\\
\begin{pgfonlayer}
{
background
}
0
&
.
8
&
\cdots
&
4
\\
\node
[draw=ugreen,fill=green!20!white,rounded corners=0.3em,minimum width=3.8cm,minimum height=0.9em,anchor=south west] (emb) at ([shift=
{
(1.25cm,0.8cm)
}
]start)
{}
;
-
1
&
-
2
&
\cdots
&
-
3
\\
\end{pgfonlayer}
.
7
&
.
5
&
\cdots
&
3
\\
-
2
&
.
3
&
\cdots
&
.
1
\draw
[decorate,decoration=
{
brace,mirror
}
] ([shift=
{
(6pt,2pt)
}
]mat.south west) to node [auto,swap,font=
\scriptsize
]
{
词嵌入矩阵
}
([shift=
{
(-6pt,2pt)
}
]mat.south east);
\end
{
bmatrix
}
$}}
;
\draw
[-latex'] ([xshift=-2pt,yshift=-0.65cm]one.east) to ([yshift=-0.65cm]words.west);
\draw
[-latex'] (emb.east) -| ([yshift=0.4cm]mat.north east) node [pos=1,above]
{
\scriptsize
{
RNN输入
}}
;
\draw
[decorate,decoration=
{
brace,mirror
}
] ([shift=
{
(6pt,2pt)
}
]mat.south west) to node [auto,swap,font=
\scriptsize
]
{
词嵌入矩阵
}
([shift=
{
(-6pt,2pt)
}
]mat.south east);
\draw
[-latex'] ([yshift=-0.4cm]w.south) to ([yshift=2pt]w.south);
\node
[anchor=north] (wlabel) at ([yshift=-0.6em]w.south)
{
\scriptsize
{
输入的单词
}}
;
\visible
<3->
{
\draw
[-latex'] ([xshift=-2pt,yshift=-0.65cm]one.east) to ([yshift=-0.65cm]words.west);
\node
[draw=ugreen,densely dashed,thick,rounded corners=3pt,fit=(one) (words) (mat) (w)] (input)
{}
;
}
\end{scope}
\visible
<4->
{
\draw
[-latex'] (emb.east) -| ([yshift=0.4cm]mat.north east) node [pos=1,above]
{
\scriptsize
{
RNN输入
}}
;
\draw
[->,thick,densely dashed,ugreen] ([yshift=-0.2em]demb3.east) to [out=0,in=180] ([yshift=-1cm]input.west);
}
\end{tikzpicture}
\draw
[-latex'] ([yshift=-0.4cm]w.south) to ([yshift=2pt]w.south);
\end{center}
\node
[anchor=north] (wlabel) at ([yshift=-0.6em]w.south)
{
\scriptsize
{
输入的单词
}}
;
\node
[draw=ugreen,densely dashed,thick,rounded corners=3pt,fit=(one) (words) (mat) (w)] (input)
{}
;
\end{scope}
\draw
[->,thick,densely dashed,ugreen] ([yshift=-0.2em]demb3.east) to [out=0,in=180] ([yshift=-1cm]input.west);
\end{tikzpicture}
\end{center}
\end{frame}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%%------------------------------------------------------------------------------------------------------------
%%% 输出
%%% 输出
\begin{frame}
{
模块2:输出层
}
\begin{frame}
{
模块2:输出层
}
\begin{itemize}
\item
输出层需要得到每个目标语单词的生成概率,进而选取概率最高的词作为输出。但RNN中的隐藏层并不会输出单词概率,而是输出
$
s
$
,其每一行对应一个单词表示
\begin{itemize}
\begin{itemize}
\item
$
s
$
经过权重矩阵
$
W
$
变成
$
\hat
{
s
}$
,其隐藏层维度变换成词表的大小
\item
输出层需要得到每个目标语单词的生成概率,进而选取概率最高的词作为输出。但RNN中的隐藏层并不会输出单词概率,而是输出
$
s
$
,其每一行对应一个单词表示
\item
$
\hat
{
s
}$
经过Softmax变换得到不同词作为输出的概率,即单词
$
i
$
的概率
$
p
_
i
=
\textrm
{
Softmax
}
(
i
)
=
\frac
{
e
^{
\hat
{
s
}_
i
}}{
\sum
_{
j
}
e
^{
\hat
{
s
}_{
j
}}}
$
\begin{itemize}
\item
<2->
$
s
$
经过权重矩阵
$
W
$
变成
$
\hat
{
s
}$
,其隐藏层维度变换成词表的大小
\item
<3->
$
\hat
{
s
}$
经过Softmax变换得到不同词作为输出的概率,即单词
$
i
$
的概率
$
p
_
i
=
\textrm
{
Softmax
}
(
i
)
=
\frac
{
e
^{
\hat
{
s
}_
i
}}{
\sum
_{
j
}
e
^{
\hat
{
s
}_{
j
}}}
$
\end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}
%%% 图
%%% 图
\begin{center}
\begin{center}
\hspace*
{
-0.6cm
}
\hspace*
{
-0.6cm
}
\begin{tikzpicture}
\begin{tikzpicture}
\setlength
{
\base
}{
0.9cm
}
\setlength
{
\base
}{
0.9cm
}
\tikzstyle
{
rnnnode
}
= [rounded corners=1pt,minimum height=0.5
\base
,minimum width=1
\base
,draw,inner sep=0pt,outer sep=0pt]
\tikzstyle
{
rnnnode
}
= [rounded corners=1pt,minimum height=0.5
\base
,minimum width=1
\base
,draw,inner sep=0pt,outer sep=0pt]
\tikzstyle
{
wordnode
}
= [font=
\tiny
]
\tikzstyle
{
wordnode
}
= [font=
\tiny
]
% RNN translation model
% RNN translation model
\begin{scope}
[local bounding box=RNNMT]
\begin{scope}
[local bounding box=RNNMT]
% RNN Encoder
% RNN Encoder
\coordinate
(eemb0) at (0,0);
\coordinate
(eemb0) at (0,0);
\foreach
\x
[count=
\y
from 0] in
{
1,2,...,3
}
\foreach
\x
[count=
\y
from 0] in
{
1,2,...,3
}
\node
[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=west]
(eemb
\x
) at ([xshift=0.4
\base
]eemb
\y
.east)
{
\tiny
{$
e
_
x
()
$}}
;
\node
[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=west]
(eemb
\x
) at ([xshift=0.4
\base
]eemb
\y
.east)
{
\tiny
{$
e
_
x
()
$}}
;
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\node
[rnnnode,fill=blue!30!white,anchor=south]
(enc
\x
) at ([yshift=0.3
\base
]eemb
\x
.north)
{}
;
\node
[rnnnode,fill=blue!30!white,anchor=south]
(enc
\x
) at ([yshift=0.3
\base
]eemb
\x
.north)
{}
;
\node
[]
(enclabel1) at (enc1)
{
\tiny
{$
\textbf
{
h
}_{
m
-
2
}$}}
;
\node
[]
(enclabel1) at (enc1)
{
\tiny
{$
\textbf
{
h
}_{
m
-
2
}$}}
;
\node
[]
(enclabel2) at (enc2)
{
\tiny
{$
\textbf
{
h
}_{
m
-
1
}$}}
;
\node
[]
(enclabel2) at (enc2)
{
\tiny
{$
\textbf
{
h
}_{
m
-
1
}$}}
;
\node
[rnnnode,fill=purple!30!white]
(enclabel3) at (enc3)
{
\tiny
{$
\textbf
{
h
}_{
m
}$}}
;
\node
[rnnnode,fill=purple!30!white]
(enclabel3) at (enc3)
{
\tiny
{$
\textbf
{
h
}_{
m
}$}}
;
\node
[wordnode,left=0.4\base of enc1]
(init1)
{$
\cdots
$}
;
\node
[wordnode,left=0.4\base of enc1]
(init1)
{$
\cdots
$}
;
\node
[wordnode,left=0.4\base of eemb1]
(init2)
{$
\cdots
$}
;
\node
[wordnode,left=0.4\base of eemb1]
(init2)
{$
\cdots
$}
;
\node
[wordnode,below=0pt of eemb1]
()
{
走
}
;
\node
[wordnode,below=0pt of eemb1]
()
{
走
}
;
\node
[wordnode,below=0pt of eemb2]
()
{
吗
}
;
\node
[wordnode,below=0pt of eemb2]
()
{
吗
}
;
\node
[wordnode,below=0pt of eemb3]
()
{$
\langle
$
eos
$
\rangle
$}
;
\node
[wordnode,below=0pt of eemb3]
()
{$
\langle
$
eos
$
\rangle
$}
;
% RNN Decoder
% RNN Decoder
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\node
[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=south]
(demb
\x
) at ([yshift=
\base
]enc
\x
.north)
{
\tiny
{$
e
_
y
()
$}}
;
\node
[rnnnode,minimum height=0.5\base,fill=green!30!white,anchor=south]
(demb
\x
) at ([yshift=
\base
]enc
\x
.north)
{
\tiny
{$
e
_
y
()
$}}
;
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\node
[rnnnode,fill=blue!30!white,anchor=south]
(dec
\x
) at ([yshift=0.3
\base
]demb
\x
.north)
{{
\tiny
{$
\textbf
{
s
}_
\x
$}}}
;
\node
[rnnnode,fill=blue!30!white,anchor=south]
(dec
\x
) at ([yshift=0.3
\base
]demb
\x
.north)
{{
\tiny
{$
\textbf
{
s
}_
\x
$}}}
;
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\node
[rnnnode,minimum height=0.5\base,fill=red!30!white,anchor=south]
(softmax
\x
) at ([yshift=0.3
\base
]dec
\x
.north)
{
\tiny
{
Softmax
}}
;
\node
[rnnnode,minimum height=0.5\base,fill=red!30!white,anchor=south]
(softmax
\x
) at ([yshift=0.3
\base
]dec
\x
.north)
{
\tiny
{
Softmax
}}
;
\node
[wordnode,right=0.4\base of demb3]
(end1)
{$
\cdots
$}
;
\node
[wordnode,right=0.4\base of demb3]
(end1)
{$
\cdots
$}
;
\node
[wordnode,right=0.4\base of dec3]
(end2)
{$
\cdots
$}
;
\node
[wordnode,right=0.4\base of dec3]
(end2)
{$
\cdots
$}
;
\node
[wordnode,right=0.4\base of softmax3]
(end3)
{$
\cdots
$}
;
\node
[wordnode,right=0.4\base of softmax3]
(end3)
{$
\cdots
$}
;
% Decoder input words
% Decoder input words
\node
[wordnode,below=0pt of demb1]
(decwordin)
{$
\langle
$
sos
$
\rangle
$}
;
\node
[wordnode,below=0pt of demb1]
(decwordin)
{$
\langle
$
sos
$
\rangle
$}
;
\ExtractX
{$
(
demb
2
.south
)
$}
\ExtractX
{$
(
demb
2
.south
)
$}
\ExtractY
{$
(
decwordin.base
)
$}
\ExtractY
{$
(
decwordin.base
)
$}
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
Do
}
;
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
Do
}
;
\ExtractX
{$
(
demb
3
.south
)
$}
\ExtractX
{$
(
demb
3
.south
)
$}
\ExtractY
{$
(
decwordin.base
)
$}
\ExtractY
{$
(
decwordin.base
)
$}
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
you
}
;
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
you
}
;
% Decoder output words
% Decoder output words
\node
[wordnode,above=0pt of softmax1]
(decwordout)
{
Do
}
;
\node
[wordnode,above=0pt of softmax1]
(decwordout)
{
Do
}
;
\ExtractX
{$
(
softmax
2
.north
)
$}
\ExtractX
{$
(
softmax
2
.north
)
$}
\ExtractY
{$
(
decwordout.base
)
$}
\ExtractY
{$
(
decwordout.base
)
$}
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
you
}
;
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
you
}
;
\ExtractX
{$
(
softmax
3
.north
)
$}
\ExtractX
{$
(
softmax
3
.north
)
$}
\ExtractY
{$
(
decwordout.base
)
$}
\ExtractY
{$
(
decwordout.base
)
$}
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
know
}
;
\node
[wordnode,anchor=base]
() at (
\XCoord
,
\YCoord
)
{
know
}
;
% Connections
% Connections
\draw
[-latex']
(init1.east) to (enc1.west);
\draw
[-latex']
(init1.east) to (enc1.west);
\draw
[-latex']
(dec3.east) to (end2.west);
\draw
[-latex']
(dec3.east) to (end2.west);
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\draw
[-latex']
(eemb
\x
) to (enc
\x
);
\draw
[-latex']
(eemb
\x
) to (enc
\x
);
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\draw
[-latex']
(demb
\x
) to (dec
\x
);
\draw
[-latex']
(demb
\x
) to (dec
\x
);
\foreach
\x
in
{
1,2,...,3
}
\foreach
\x
in
{
1,2,...,3
}
\draw
[-latex']
(dec
\x
.north) to (softmax
\x
.south);
\draw
[-latex']
(dec
\x
.north) to (softmax
\x
.south);
\foreach
\x
[count=
\y
from 2] in
{
1,2
}
\foreach
\x
[count=
\y
from 2] in
{
1,2
}
{
{
\draw
[-latex']
(enc
\x
.east) to (enc
\y
.west);
\draw
[-latex']
(enc
\x
.east) to (enc
\y
.west);
\draw
[-latex']
(dec
\x
.east) to (dec
\y
.west);
\draw
[-latex']
(dec
\x
.east) to (dec
\y
.west);
}
}
\coordinate
(bridge) at ([yshift=0.4
\base
]enc2.north west);
\coordinate
(bridge) at ([yshift=0.4
\base
]enc2.north west);
\draw
[-latex']
(enc3.north) .. controls +(north:0.3
\base
) and +(east:
\base
) .. (bridge) .. controls +(west:2.7
\base
) and +(west:0.3
\base
) .. (dec1.west);
\draw
[-latex']
(enc3.north) .. controls +(north:0.3
\base
) and +(east:
\base
) .. (bridge) .. controls +(west:2.7
\base
) and +(west:0.3
\base
) .. (dec1.west);
\end{scope}
\end{scope}
\begin{scope}
\begin{scope}
\coordinate
(start) at (8.5
\base
,0.1
\base
);
\coordinate
(start) at (8.5
\base
,0.1
\base
);
\node
[anchor=center,minimum width=5.7em,minimum height=1.3em,draw,rounded corners=0.3em] (hidden) at (start)
{}
;
\node
[anchor=center,minimum width=5.7em,minimum height=1.3em,draw,rounded corners=0.3em] (hidden) at (start)
{}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!20] (cell01) at ([xshift=0.2em]hidden.west)
{
\scriptsize
{
.2
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!20] (cell01) at ([xshift=0.2em]hidden.west)
{
\scriptsize
{
.2
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell02) at (cell01.east)
{
\scriptsize
{
-1
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell02) at (cell01.east)
{
\scriptsize
{
-1
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=white] (cell03) at (cell02.east)
{
\scriptsize
{$
\cdots
$}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=white] (cell03) at (cell02.east)
{
\scriptsize
{$
\cdots
$}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!50] (cell04) at (cell03.east)
{
\scriptsize
{
5
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!50] (cell04) at (cell03.east)
{
\scriptsize
{
5
}}
;
\visible
<2->
{
\node
[anchor=south,minimum width=10.9em,minimum height=1.3em,draw,rounded corners=0.3em] (target) at ([yshift=1.5em]hidden.north)
{}
;
\node
[anchor=south,minimum width=10.9em,minimum height=1.3em,draw,rounded corners=0.3em] (target) at ([yshift=1.5em]hidden.north)
{}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell11) at ([xshift=0.2em]target.west)
{
\scriptsize
{
-2
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell11) at ([xshift=0.2em]target.west)
{
\scriptsize
{
-2
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell12) at (cell11.east)
{
\scriptsize
{
-1
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell12) at (cell11.east)
{
\scriptsize
{
-1
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell13) at (cell12.east)
{
\scriptsize
{
.7
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!30] (cell13) at (cell12.east)
{
\scriptsize
{
.7
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=white] (cell14) at (cell13.east)
{
\scriptsize
{$
\cdots
$}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=white] (cell14) at (cell13.east)
{
\scriptsize
{$
\cdots
$}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!30] (cell15) at (cell14.east)
{
\scriptsize
{
6
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!70] (cell15) at (cell14.east)
{
\scriptsize
{
6
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!70] (cell16) at (cell15.east)
{
\scriptsize
{
-3
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell16) at (cell15.east)
{
\scriptsize
{
-3
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell17) at (cell16.east)
{
\scriptsize
{
-1
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!10] (cell17) at (cell16.east)
{
\scriptsize
{
-1
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!20] (cell18) at (cell17.east)
{
\scriptsize
{
.2
}}
;
\node
[anchor=west,minimum width=1em,minimum size=1em,fill=ugreen!20] (cell18) at (cell17.east)
{
\scriptsize
{
.2
}}
;
}
\node
[anchor=south,minimum width=1em,minimum height=0.2em,fill=ublue!80,inner sep=0pt] (label1) at ([yshift=2.5em]cell11.north)
{}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w1) at (label1.north)
{$
\langle
$
eos
$
\rangle
$}
;
\visible
<3->
{
\node
[anchor=south,minimum width=1em,minimum height=0.3em,fill=ublue!80,inner sep=0pt] (label2) at ([yshift=2.5em]cell12.north)
{}
;
\node
[anchor=south,minimum width=1em,minimum height=0.2em,fill=ublue!80,inner sep=0pt] (label1) at ([yshift=2.5em]cell11.north)
{}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w2) at (label2.north)
{$
\langle
$
sos
$
\rangle
$}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w1) at (label1.north)
{$
\langle
$
eos
$
\rangle
$}
;
\node
[anchor=south,minimum width=1em,minimum height=0.5em,fill=ublue!80,inner sep=0pt] (label3) at ([yshift=2.5em]cell13.north)
{}
;
\node
[anchor=south,minimum width=1em,minimum height=0.3em,fill=ublue!80,inner sep=0pt] (label2) at ([yshift=2.5em]cell12.north)
{}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w3) at (label3.north)
{
Do
}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w2) at (label2.north)
{$
\langle
$
sos
$
\rangle
$}
;
\node
[anchor=south,font=
\scriptsize
] (w4) at ([yshift=2.5em]cell14.north)
{$
\cdots
$}
;
\node
[anchor=south,minimum width=1em,minimum height=0.5em,fill=ublue!80,inner sep=0pt] (label3) at ([yshift=2.5em]cell13.north)
{}
;
\node
[anchor=south,minimum width=1em,minimum height=1em,fill=ublue!80,inner sep=0pt] (label5) at ([yshift=2.5em]cell15.north)
{}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w3) at (label3.north)
{
Do
}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w5) at (label5.north)
{{
\color
{
red
}
know
}}
;
\node
[anchor=south,font=
\scriptsize
] (w4) at ([yshift=2.5em]cell14.north)
{$
\cdots
$}
;
\node
[anchor=south,minimum width=1em,minimum height=0.1em,fill=ublue!80,inner sep=0pt] (label6) at ([yshift=2.5em]cell16.north)
{}
;
\node
[anchor=south,minimum width=1em,minimum height=1em,fill=ublue!80,inner sep=0pt] (label5) at ([yshift=2.5em]cell15.north)
{}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w6) at (label6.north)
{
you
}
;
\alt
<4->
\node
[anchor=south,minimum width=1em,minimum height=0.3em,fill=ublue!80,inner sep=0pt] (label7) at ([yshift=2.5em]cell17.north)
{}
;
{
\node
[anchor=west,rotate=90,font=
\tiny
] (w7) at (label7.north)
{
?
}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w5) at (label5.north)
{{
\color
{
red
}
know
}}
;
\node
[anchor=south,minimum width=1em,minimum height=0.4em,fill=ublue!80,inner sep=0pt] (label8) at ([yshift=2.5em]cell18.north)
{}
;
}
\node
[anchor=west,rotate=90,font=
\tiny
] (w8) at (label8.north)
{
have
}
;
{
\node
[anchor=west,rotate=90,font=
\tiny
] (w5) at (label5.north)
{
know
}
;
\filldraw
[fill=red!20,draw=white] (target.south west) -- (target.south east) -- ([xshift=-0.2em,yshift=0.1em]hidden.north east) -- ([xshift=0.2em,yshift=0.1em]hidden.north west);
}
\draw
[->,thick] ([xshift=0.2em,yshift=0.1em]hidden.north west) -- (target.south west);
\node
[anchor=south,minimum width=1em,minimum height=0.1em,fill=ublue!80,inner sep=0pt] (label6) at ([yshift=2.5em]cell16.north)
{}
;
\draw
[->,thick] ([xshift=-0.2em,yshift=0.1em]hidden.north east) -- (target.south east);
\node
[anchor=west,rotate=90,font=
\tiny
] (w6) at (label6.north)
{
you
}
;
\node
[anchor=south,minimum width=1em,minimum height=0.3em,fill=ublue!80,inner sep=0pt] (label7) at ([yshift=2.5em]cell17.north)
{}
;
\node
[rounded corners=0.3em] (softmax) at ([yshift=1.25em]target.north)
{
\scriptsize
{$
p
(
\hat
{
s
}_
i
)=
\frac
{
e
^{
\hat
{
s
}_
i
}}{
\sum
_
j e
^{
\hat
{
s
}_
j
}}$}}
;
\node
[anchor=west,rotate=90,font=
\tiny
] (w7) at (label7.north)
{
?
}
;
\begin{pgfonlayer}
{
background
}
\node
[anchor=south,minimum width=1em,minimum height=0.4em,fill=ublue!80,inner sep=0pt] (label8) at ([yshift=2.5em]cell18.north)
{}
;
\filldraw
[fill=blue!20,draw=white] ([yshift=0.1em]cell11.north west)
{
[rounded corners=0.3em] -- (softmax.west)
}
-- (label1.south west) -- (label8.south east)
{
[rounded corners=0.3em] -- (softmax.east)
}
-- ([yshift=0.1em]cell18.north east) -- ([yshift=0.1em]cell11.north west);
\node
[anchor=west,rotate=90,font=
\tiny
] (w8) at (label8.north)
{
have
}
;
\end{pgfonlayer}
}
\node
[anchor=south] () at ([yshift=0.3em]hidden.north)
{
\scriptsize
{$
\hat
{
s
}
=
Ws
$}}
;
\visible
<2->
{
\draw
[-latex'] ([yshift=-0.3cm]hidden.south) to (hidden.south);
\filldraw
[fill=red!20,draw=white] (target.south west) -- (target.south east) -- ([xshift=-0.2em,yshift=0.1em]hidden.north east) -- ([xshift=0.2em,yshift=0.1em]hidden.north west);
\draw
[-latex'] (w5.east) to ([yshift=0.3cm]w5.east);
\draw
[->,thick] ([xshift=0.2em,yshift=0.1em]hidden.north west) -- (target.south west);
\draw
[->,thick] ([xshift=-0.2em,yshift=0.1em]hidden.north east) -- (target.south east);
\coordinate
(tmp) at ([yshift=-3pt]w5.east);
\node
[draw=red,thick,densely dashed,rounded corners=3pt,inner sep=5pt,fit=(cell01) (cell11) (label1) (label8) (target) (hidden) (tmp)] (output)
{}
;
\node
[anchor=south] () at ([yshift=0.3em]hidden.north)
{
\scriptsize
{$
\hat
{
s
}
=
Ws
$}}
;
\end{scope}
}
\draw
[->,thick,densely dashed,red] ([yshift=-0.2em]softmax3.east) .. controls +(east:2
\base
) and +(west:
\base
) .. (output.west);
\visible
<3->
{
\end{tikzpicture}
\node
[rounded corners=0.3em] (softmax) at ([yshift=1.25em]target.north)
{
\scriptsize
{$
p
(
\hat
{
s
}_
i
)=
\frac
{
e
^{
\hat
{
s
}_
i
}}{
\sum
_
j e
^{
\hat
{
s
}_
j
}}$}}
;
\end{center}
\filldraw
[fill=blue!20,draw=white] ([yshift=0.1em]cell11.north west)
{
[rounded corners=0.3em] -- (softmax.west)
}
-- (label1.south west) -- (label8.south east)
{
[rounded corners=0.3em] -- (softmax.east)
}
-- ([yshift=0.1em]cell18.north east) -- ([yshift=0.1em]cell11.north west);
\node
[rounded corners=0.3em] (softmax) at ([yshift=1.25em]target.north)
{
\scriptsize
{$
p
(
\hat
{
s
}_
i
)=
\frac
{
e
^{
\hat
{
s
}_
i
}}{
\sum
_
j e
^{
\hat
{
s
}_
j
}}$}}
;
}
\draw
[-latex'] ([yshift=-0.3cm]hidden.south) to (hidden.south);
\visible
<4->
{
\draw
[-latex'] (w5.east) to ([yshift=0.3cm]w5.east);
}
\coordinate
(tmp) at ([yshift=-3pt]w5.east);
\node
[draw=red,thick,densely dashed,rounded corners=3pt,inner sep=5pt,fit=(cell01) (cell11) (label1) (label8) (target) (hidden) (tmp)] (output)
{}
;
\end{scope}
\draw
[->,thick,densely dashed,red] ([yshift=-0.2em]softmax3.east) .. controls +(east:2
\base
) and +(west:
\base
) .. (output.west);
\end{tikzpicture}
\end{center}
\end{frame}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%%------------------------------------------------------------------------------------------------------------
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论