Lecture 4_Extra Reccurrent Neural Network (RNN)

Lecture 4_Extra Recurrent Neural Network (RNN)

RNN

Example Application

Slot Filling

image-20220912095418295

如上图所示,一些智能客服能够将一句话中的 “词语” 对应到相应的 slot 中。

要怎么做呢?可以将词语向量化后输入到一个网络中。

image-20220912095757537

怎么将词语向量化呢?

1-of-N encoding
image-20220912095957968
Beyond 1-of-N encoding
image-20220912100728920 image-20220912100949447

如下图所示,对于 feed forward 的网络来说,input 相同的东西,那么输出也会是相同的东西,而不会与上下文信息(比如,时间)相关联。—— 我们期待 neural network 有 “记忆” 的功能,能够记住不同的上下文,从而对相同的输入产生不同的输出。—— 引入 Reccurrent Neural Network (RNN)。

image-20220912101453387

Recurrent Neural Network

image-20220912101639537

Example

image-20220912102230443

如上图所示,处理接收到的序列,先处理 [ 1 1 ] \begin{bmatrix}1\\1\end{bmatrix} [11]

① 一些前提与基本假设;

② 处理 [ 1 1 ] \begin{bmatrix}1\\1\end{bmatrix} [11]

③ 对 m e m o r y memory memory 设置处置 0 0 0

④ 输入 [ 1 1 ] \begin{bmatrix}1\\1\end{bmatrix} [11],经过处理得到 2 2 2,并存入 m e m o r y memory memory

⑤ 得到输出序列 [ 4 4 ] \begin{bmatrix}4\\4\end{bmatrix} [44]

image-20220912104939477

接下来,处理下一个 [ 1 1 ] \begin{bmatrix}1\\1\end{bmatrix} [11]

( 1 + 2 ) + ( 1 + 2 ) = 6 (1+2)+(1+2)=6 (1+2)+(1+2)=6;将 6 6 6 存入 m e m o r y memory memory 6 + 6 = 12 6+6=12 6+6=12;输出 [ 12 12 ] \begin{bmatrix}12\\12\end{bmatrix} [1212]

由此可见,即使 RNN 有相同的输入,也会得到不同的输出。改变输入顺序也会改变输出(这是显然的, m e m o r y memory memory 中的内容会改变)。

上文提到的[问题](#Slot Filling),用 RNN 处理起来如下图所示。

image-20220912105746198 image-20220912110227014

Elman Network & Jordan Network

image-20220912110653028

Bidirectional RNN

image-20220912110949102

网络看过的范围更广。

Long Short-Term Memory (LSTM)

image-20220912111434220

四个输入:操控 Input Gate、Output Gate、Forget Gate 和 是否存入 Memory Cell 的信号;

只会有一个输出。

更新 Memory Cell 中的值 c c c:

image-20220912113701370

可以看出, g ( z ) g(z) g(z) 是控制输入 f ( z i ) f(z_i) f(zi) 是否有效的 “gate”(当 g ( z ) g(z) g(z) 等于 0 0 0 时,就相当于没有输入)。

f ( z f ) f(z_f) f(zf) 决定了是否更新 memory cell 中的数值。当 f ( z f ) = 1 f(z_f)=1 f(zf)=1,forget gate 开启, c c c 直接通过,不更新 c c c(也就是不遗忘 memory cell 中的内容);当 f ( z f ) = 0 f(z_f)=0 f(zf)=0,forget gate 关闭, c f ( z f ) = 0 cf(z_f)=0 cf(zf)=0 c ′ = g ( z ) f ( z i ) + c f ( z f ) c'=g(z)f(z_i)+cf(z_f) c=g(z)f(zi)+cf(zf),进行更新(也就是遗忘了原 memory cell 中的内容)。

image-20220912114915811

f ( z 0 ) f(z_0) f(z0) 控制 Output Gate 的输出。

LSTM-Example
image-20220912115715825

如上图所示,是一个模拟 LSTM 的简单例子。列出了一些规则(假设),并进行相应的 memory cell 和 output 的计算。

image-20220912151420039 image-20220912152018412
Learning Target
image-20220914163231642

输入训练的语句,每个词语对应一个 slot(arrive、on 对应到 other,Taipei 对应到 destination,November、2nd 对应到 time);经过 RNN 后得到输出 y i y^{i} yi reference vector \text{reference vector} reference vector(长度为不同 slot 的个数,词语属于哪一个 slot,该 slot 的值就是 1 1 1)计算交叉熵损失(Cross-Entropy)。需要最小化的对象就是所有的交叉熵损失函数之和。

image-20220914164439839

RNN 是可以利用 Gradient Descend 训练的,但训练过程较为困难。

image-20220914164655727

我们期待训练过程如上图蓝线所示,但有时候会像绿线所示。RNN 的 error surface \text{error surface} error surface 较为复杂:

image-20220914165631145

g r a d i e n t gradient gradient 超过某 t h r e s h o l d threshold threshold 时,就不让 g r a d i e n t gradient gradient 继续增加,而让 g r a d i e n t gradient gradient 等于一个固定的(fixed)值(这就是所谓的 c l i p p i n g clipping clipping)。

为什么训练 RNN 会存在如此大的波动呢?有人认为是 activation funciotn \text{activation funciotn} activation funciotn 的问题,通常用 R e L U ReLU ReLU 的效果不会很好,个人感觉李宏毅老师认为是梯度带来的问题🤔。下面是一个简单的例子,假设 input、output 的权重都是 1 1 1,memory cell 值传输到下个 neuron 的权重为 w w w,当 1000 1000 1000 个 neuron 叠加后,对 w w w 取值的简单讨论如下图所示,可以看出 g r a d i e n t gradient gradient 的变化程度是非常大的。

image-20220914170500153

如何缓解这种问题呢?

LSTM 能够解决梯度消失(而不能解决梯度爆炸)。—— 这又是为什么呢?如下图 ①② 所示。

image-20220914185047169

GRU 的参数量较 LSTM 少,在 LSTM 过拟合时,可以考虑使用 GRU。

image-20220914185933571

More Applications

image-20220914190255969

Many to one

输入是向量序列,而输出只是一个向量。

Sentiment Analysis
image-20220914190611758
Key Term Extraction
image-20220914190741319

Many to Many (Output is shorter)

输入输出都是序列,但输出更短。

Speech Recognition
image-20220914191340831 image-20220914191634094

Many to Many (No Limitation)

输入输出都是序列,对长度没有限制 → Sequence to sequence learning

Machine Translation
image-20220914193120058 image-20220914193312463

Beyond Sequence

Syntactic parsing
image-20220914194000299

Sequence-to-sequence Auto-encoder - Text

image-20220914194158343

Sequence-to-sequence Auto-encoder - Speech

image-20220914194502855
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值