学习笔记 NLP里的RNN和LSTM

1. Recurrent neural network

Recurrent_neural_network_unfold.svg

1.1 Elman network

h t = σ h ( W h x t + U h h t − 1 + b h ) h_{t}=\sigma_{h}\left(W_{h} x_{t}+U_{h} h_{t-1}+b_{h}\right) ht=σh(Whxt+Uhht1+bh)

y t = σ y ( W y h t + b y ) y_{t}=\sigma_{y}\left(W_{y} h_{t}+b_{y}\right) yt=σy(Wyht+by)

1.2 Jordan network

h t = σ h ( W h x t + U h y t − 1 + b h ) h_{t}=\sigma_{h}\left(W_{h} x_{t}+U_{h} y_{t-1}+b_{h}\right) ht=σh(Whxt+Uhyt1+bh)

y t = σ y ( W y h t + b y ) y_{t}=\sigma_{y}\left(W_{y} h_{t}+b_{y}\right) yt=σy(Wyht+by)

Variables and functions

  • x t x_{t} xt : input vector
  • h t h_{t} ht : hidden layer vector
  • y t y_{t} yt : output vector
  • W , U W, U W,U and b b b : parameter matrices and vector
  • σ h \sigma_{h} σh and σ y \sigma_{y} σy : Activation functions
1.3 Bidirectional RNN

2. Long short-term memory

2.1 LSTM with a forget gate

The compact forms of the equations for the forward pass of an LSTM cell with a forget gate are:
f t = σ g ( W f x t + U f h t − 1 + b f ) i t = σ g ( W i x t + U i h t − 1 + b i ) o t = σ g ( W o x t + U o h t − 1 + b o ) c ~ t = σ c ( W c x t + U c h t − 1 + b c ) c t = f t ∘ c t − 1 + i t ∘ c ~ t h t = o t ∘ σ h ( c t ) \begin{aligned} f_{t} &=\sigma_{g}\left(W_{f} x_{t}+U_{f} h_{t-1}+b_{f}\right) \\ i_{t} &=\sigma_{g}\left(W_{i} x_{t}+U_{i} h_{t-1}+b_{i}\right) \\ o_{t} &=\sigma_{g}\left(W_{o} x_{t}+U_{o} h_{t-1}+b_{o}\right) \\ \tilde{c}_{t} &=\sigma_{c}\left(W_{c} x_{t}+U_{c} h_{t-1}+b_{c}\right) \\ c_{t} &=f_{t} \circ c_{t-1}+i_{t} \circ \tilde{c}_{t} \\ h_{t} &=o_{t} \circ \sigma_{h}\left(c_{t}\right) \end{aligned} ftitotc~tctht=σg(Wfxt+Ufht1+bf)=σg(Wixt+Uiht1+bi)=σg(Woxt+Uoht1+bo)=σc(Wcxt+Ucht1+bc)=ftct1+itc~t=otσh(ct)
where the initial values are c 0 = 0 c_{0}=0 c0=0 and h 0 = 0 h_{0}=0 h0=0 and the operator o denotes the Hadamard product (element-wise product). The subscript t t t indexes the time step.
Variables

  • x t ∈ R d x_{t} \in \mathbb{R}^{d} xtRd : input vector to the LSTM unit
  • f t ∈ ( 0 , 1 ) h f_{t} \in(0,1)^{h} ft(0,1)h : forget gate’s activation vector
  • i t ∈ ( 0 , 1 ) h : i_{t} \in(0,1)^{h}: it(0,1)h: input/update gate’s activation vector
  • o t ∈ ( 0 , 1 ) h o_{t} \in(0,1)^{h} ot(0,1)h : output gate’s activation vector
  • h t ∈ ( − 1 , 1 ) h h_{t} \in(-1,1)^{h} ht(1,1)h : hidden state vector also known as output vector of the LSTM unit
  • c ~ t ∈ ( − 1 , 1 ) h : \tilde{c}_{t} \in(-1,1)^{h}: c~t(1,1)h: cell input activation vector
  • c t ∈ R h c_{t} \in \mathbb{R}^{h} ctRh : cell state vector
  • W ∈ R h × d , U ∈ R h × h W \in \mathbb{R}^{h \times d}, U \in \mathbb{R}^{h \times h} WRh×d,URh×h and b ∈ R h b \in \mathbb{R}^{h} bRh : weight matrices and bias vector parameters which need to be learned during training where the superscripts d d d and h h h refer to the number of input features and number of hidden units, respectively.
2.2 Peephole LSTM

f t = σ g ( W f x t + U f c t − 1 + b f ) i t = σ g ( W i x t + U i c t − 1 + b i ) o t = σ g ( W o x t + U o c t − 1 + b o ) c t = f t ∘ c t − 1 + i t ∘ σ c ( W c x t + b c ) h t = o t ∘ σ h ( c t ) \begin{aligned} f_{t} &=\sigma_{g}\left(W_{f} x_{t}+U_{f} c_{t-1}+b_{f}\right) \\ i_{t} &=\sigma_{g}\left(W_{i} x_{t}+U_{i} c_{t-1}+b_{i}\right) \\ o_{t} &=\sigma_{g}\left(W_{o} x_{t}+U_{o} c_{t-1}+b_{o}\right) \\ c_{t} &=f_{t} \circ c_{t-1}+i_{t} \circ \sigma_{c}\left(W_{c} x_{t}+b_{c}\right) \\ h_{t} &=o_{t} \circ \sigma_{h}\left(c_{t}\right) \end{aligned} ftitotctht=σg(Wfxt+Ufct1+bf)=σg(Wixt+Uict1+bi)=σg(Woxt+Uoct1+bo)=ftct1+itσc(Wcxt+bc)=otσh(ct)

3. training RNN

3.1 Problem

RNN: The error surface is either very flat or very steep → 梯度消失/爆炸 Gradient Vanishing/Exploding

绘图1

3.2 Techniques
  • Clipping the gradients
  • Advanced optimization technology
    • NAG
    • RMSprop
  • Try LSTM (or other simpler variants)
    • Can deal with gradient vanishing (not gradient explode)
    • Memory and input are added (在RNN中,对于每一个输入,memory会重置)
    • The influence never disappears unless forget gate is closed (No Gradient vanishing, if forget gate is opened.)
  • Better initialization
    • Vanilla RNN Initialized with Identity matrix + ReLU activation function [Quoc V. Le, arXiv’15]

参考资料

[1] Recurrent neural network - Wikipedia

[2] Long short-term memory - Wikipedia

[3] Bidirectional Recurrent Neural Networks - Dive into Deep …

[4] 机器学习 李宏毅

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习、深度学习自然语言处理等人工智能基础知识总结以及源代码.zip 说明 机器学习、深度学习自然语言处理基础知识总结。 目前主要参考李航老师的《统计学习方法》一书,也有一些内容例如XGBoost、聚类、深度学习相关内容、NLP相关内容等是书中未提及的。 由于github的markdown解析器不支持latex,因此笔记部分需要在本地使用Typora才能正常浏览,也可以直接访问下面给出的博客链接。 Document文件夹下为笔记,Code文件夹下为代码,Data文件夹下为某些代码所使用的数据集,Image文件夹下为笔记部分所用到的图片。 由于时间和精力有限,部分代码来自github开源项目,如Seq2Seq、Transformer等部分的代码,部分章节代码待补充。 机器学习 线性回归(笔记) 感知机(笔记+代码) KNN(笔记+代码) 朴素贝叶斯(笔记+代码) 决策树(笔记+代码) 逻辑回归(笔记+代码) 最大熵(笔记+代码) SVM(笔记+代码) AdaBoost(笔记+代码) GBDT(笔记+代码) EM算法(笔记+代码) 隐马尔可夫模型(笔记+代码) 条件随机场(笔记) 随机森林(笔记+代码) XGBoost(笔记) 聚类(笔记) 特征工程之特征选择(笔记) 特征工程之降维算法(笔记) 深度学习 神经网络(笔记+代码) RNN(笔记) LSTM和GRU(笔记) CNN(笔记) 深度学习中的最优化方法(笔记自然语言处理 词嵌入之Word2Vec(笔记) 词嵌入之GloVe(笔记) 词嵌入之FastText(笔记) TextCNN(笔记+代码) Seq2Seq(笔记+代码) Transformer(笔记+代码) BERT(笔记LSTM+CRF进行序列标注(笔记) 主题模型(笔记
Coursera深度学习教程中文笔记 课程概述 这些课程专为已有一定基础(基本的编程知识,熟悉Python、对机器学习有基本了解), 想要尝试进入人工智能领域的计算机专业人士准备。介绍显示:“深度学习是科技业最热门 的技能之一,本课程将帮你掌握深度学习。” 在这5堂课中,学生将可以学习到深度学习的基础,学会构建神经网络,并用在包括吴 恩达本人在内的多位业界顶尖专家指导下创建自己的机器学习项目。Deep Learning Specialization对卷积神经网络 (CNN)、递归神经网络 (RNN)、长短期记忆 (LSTM) 等深度学 习常用的网络结构、工具和知识都有涉及。 课程中也会有很多实操项目,帮助学生更好地应用自己学到的深度学习技术,解决真实 世界问题。这些项目将涵盖医疗、自动驾驶、和自然语言处理等时髦领域,以及音乐生成等 等。Coursera上有一些特定方向和知识的资料,但一直没有比较全面、深入浅出的深度学习 课程——《深度学习专业》的推出补上了这一空缺。 课程的语言是Python,使用的框架是Google开源的TensorFlow。最吸引人之处在于, 课程导师就是吴恩达本人,两名助教均来自斯坦福计算机系。完成课程所需时间根据不同的 学习进度,大约需要3-4个月左右。学生结课后,Coursera将授予他们Deep Learning Specialization结业证书。 “我们将帮助你掌握深度学习,理解如何应用深度学习,在人工智能业界开启你的职业 生涯。”吴恩达在课程页面中提到。 本人黄海广博士,以前写过吴恩达老师的机器学习个人笔记。有朋友报名了课程,下载 了这次课程的视频给大家分享。Coursera的字幕不全,同学们在学习上感觉非常不方便,因 此我找志同道合的朋友翻译和整理字幕,中英文字幕来自于由我和曹骁威同学组织爱好者翻 译,希望对大家有所帮助。(备注:自网易公开课翻译深度学习课程后,我们不再翻译) 目前我正在组织团队整理中文笔记,由热心的朋友无偿帮忙制作整理,并持续更新。我 们的团队的劳动致力于AI在国内的推广,不会损害Coursera以及吴恩达老师的商业利益。 本人水平有限,如有公式、算法错误,请及时指出,发邮件给我,也可以加我qq。 黄海广

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值