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
NiuTrans
Toy-MT-Introduction
Commits
a10f27e4
Commit
a10f27e4
authored
Oct 22, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new pages
parent
c7c13816
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
69 行增加
和
21 行删除
+69
-21
Section05-Neural-Networks-and-Language-Modeling/section05-test.tex
+69
-21
Section05-Neural-Networks-and-Language-Modeling/section05.tex
+0
-0
没有找到文件。
Section05-Neural-Networks-and-Language-Modeling/section05-test.tex
查看文件 @
a10f27e4
...
...
@@ -118,31 +118,79 @@
%%%------------------------------------------------------------------------------------------------------------
\subsection
{
前馈、循环、自注意力神经网络
}
%%%------------------------------------------------------------------------------------------------------------
%%% n-gram语言模型
\begin{frame}
{$
n
$
-gram语言模型
}
%%% FNNLM implementation
\begin{frame}
{
前馈神经网络语言模型的实现
}
\begin{itemize}
\item
\textbf
{
链式法则
}
\begin{eqnarray}
\textrm
{
P
}
(w
_
1 w
_
2 ... w
_
m)
&
=
&
\textrm
{
P
}
(w
_
1)
\textrm
{
P
}
(w
_
2|w
_
1)
\textrm
{
P
}
(w
_
3 | w
_
1 w
_
2) ...
\nonumber
\\
&
&
\textrm
{
P
}
(w
_
m|w
_
1...w
_{
n-1
}
)
\nonumber
\end{eqnarray}
\item
\textbf
{
传统
$
n
$
-gram语言模型
}
:当前词仅依赖于前面
$
n
-
1
$
个词
\begin{eqnarray}
\textrm
{
P
}
(w
_
1 w
_
2 ... w
_
m)
&
=
&
\textrm
{
P
}
(w
_
1)
\textrm
{
P
}
(w
_
2|w
_
1)
\textrm
{
P
}
(w
_
3 | w
_
1 w
_
2) ...
\nonumber
\\
&
&
\textrm
{
P
}
(w
_
m|
\underbrace
{
w
_{
m-n+1
}
...w
_{
m-1
}}_{
\text
{
前面
$
n
-
1
$
个词
}}
)
\nonumber
\end{eqnarray}
\ \ \ \ \ \
其中
\begin{displaymath}
\textrm
{
P
}
(w
_
m | w
_{
m-n+1
}
... w
_{
m-1
}
) =
\frac
{
\textrm
{
count
}
(w
_{
m-n+1
}
...w
_{
m
}
)
}{
\textrm
{
count
}
(w
_{
m-n+1
}
...w
_{
m-1
}
)
}
\end{displaymath}
\ \ \ \ \ \
$
\textrm
{
count
}
(
\cdot
)
$
表示在训练数据上统计的频次
\item
实现非常简单,几行代码
\begin{itemize}
\item
细节1:做batching时可以把
$
w
[
i
]
$
进行扩展,比如放入多个词
\item
细节2:TanH一般会用HardTanH实现,因为TanH容易溢出
\end{itemize}
\end{itemize}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
%%% 前馈神经网络语言模型
\begin{frame}
{$
n
$
-gram生成概率的神经网络建模
}
\begin{tcolorbox}
[bicolor,sidebyside,righthand width=3.8cm,size=title,frame engine=empty,
colback=blue!10!white,colbacklower=black!5!white]
{
\scriptsize
\begin{tabbing}
\texttt
{
XTensor w[3], e[3], h0, y;
}
\\
\texttt
{
XTensor C, H, d, U;
}
\\
\texttt
{
...
}
\\
\texttt
{}
\\
\texttt
{
for(unsigned i = 0; i < 3; i++)
\{
}
\\
\texttt
{
\ \ \ \
e[i] = MMul(w[i], C);
}
\\
\texttt
{
\}
}
\\
\texttt
{
e01 = Concatenate(e[0], e[1], -1);
}
\\
\texttt
{
e = Concatenate(e01, e[2], -1);
}
\\
\texttt
{}
\\
\texttt
{
h0 = TanH(MMul(e, H) + d);
}
\\
\texttt
{
y = Softmax(MMul(h0, U));
}
\\
\texttt
{}
\\
\texttt
{
for(unsigned k = 0; k < size; k++)
\{
}
\\
\texttt
{}
\ \ \ \
... //
\alert
{
\texttt
{
y
}}
的第
$
k
$
元素表示
$
\textrm
{
P
}
(
w|...
)
$
\\
\texttt
{}
\ \ \ \
... //
$
w
$
为词汇表里第
$
k
$
个词
\\
\texttt
{
\}
}
\end{tabbing}
}
\tcblower
\begin{center}
\begin{tikzpicture}
\begin{scope}
\node
[anchor=west] (w0) at (0,0)
{
\scriptsize
{$
w
_{
i
-
3
}$}}
;
\node
[anchor=west] (w1) at ([xshift=0.5em]w0.east)
{
\scriptsize
{$
w
_{
i
-
2
}$}}
;
\node
[anchor=west] (w2) at ([xshift=0.5em]w1.east)
{
\scriptsize
{$
w
_{
i
-
1
}$}}
;
\node
[anchor=north] (index0) at ([yshift=0.5em]w0.south)
{
\tiny
(index)
}
;
\node
[anchor=north] (index1) at ([yshift=0.5em]w1.south)
{
\tiny
(index)
}
;
\node
[anchor=north] (index2) at ([yshift=0.5em]w2.south)
{
\tiny
(index)
}
;
\node
[anchor=south,draw,inner sep=3pt,align=left] (e0) at ([yshift=1.0em]w0.north)
{
\tiny
{$
e
_
0
:
$}
\\\tiny
{$
w
_{
i
-
3
}
\textbf
{
C
}$}}
;
\node
[anchor=south,draw,inner sep=3pt,align=left] (e1) at ([yshift=1.0em]w1.north)
{
\tiny
{$
e
_
1
:
$}
\\\tiny
{$
w
_{
i
-
2
}
\textbf
{
C
}$}}
;
\node
[anchor=south,draw,inner sep=3pt,align=left] (e2) at ([yshift=1.0em]w2.north)
{
\tiny
{$
e
_
2
:
$}
\\\tiny
{$
w
_{
i
-
1
}
\textbf
{
C
}$}}
;
\node
[anchor=south,draw,minimum width=9em,inner sep=3pt] (h0) at ([yshift=1.5em]e1.north)
{
\tiny
{$
h
_
0
=
\textrm
{
Tanh
}
([
e
_
0
,e
_
1
,e
_
2
]
\textbf
{
H
}
+
\textbf
{
d
}
)
$}}
;
\node
[anchor=south,draw,minimum width=9em,inner sep=3pt] (h1) at ([yshift=1.5em]h0.north)
{
\tiny
{$
y
=
\textrm
{
Softmax
}
(
h
_
0
\textbf
{
U
}
)
$}}
;
\node
[anchor=south] (ylabel) at ([yshift=1em]h1.north)
{
\scriptsize
{$
\textrm
{
P
}
(
w
_
i|w
_{
i
-
3
}
w
_{
i
-
2
}
w
_{
i
-
1
}
)
$}}
;
\draw
[->] ([yshift=0.1em]w0.north) -- ([yshift=-0.1em]e0.south);
\draw
[->] ([yshift=0.1em]w1.north) -- ([yshift=-0.1em]e1.south);
\draw
[->] ([yshift=0.1em]w2.north) -- ([yshift=-0.1em]e2.south);
\draw
[->] ([yshift=0.1em]e0.north) -- ([xshift=-2em,yshift=-0.1em]h0.south);
\draw
[->] ([yshift=0.1em]e1.north) -- ([yshift=-0.1em]h0.south);
\draw
[->] ([yshift=0.1em]e2.north) -- ([xshift=2em,yshift=-0.1em]h0.south);
\draw
[->] ([yshift=0.1em]h0.north) -- ([yshift=-0.1em]h1.south);
\draw
[->] ([yshift=0.1em]h1.north) -- ([yshift=-0.1em]ylabel.south);
\end{scope}
\end{tikzpicture}
\end{center}
\end{tcolorbox}
\vspace
{
-0.5em
}
\footnotesize
{
注: size表示词汇表大小
}
\end{frame}
%%%------------------------------------------------------------------------------------------------------------
...
...
Section05-Neural-Networks-and-Language-Modeling/section05.tex
查看文件 @
a10f27e4
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论