NG Andrew deep learning五 序列模型

一、循环序列模型

1.1 why sequence models?
其实,不仅仅是语音/音乐/文字这种长条状顺序出现的序列需要用序列模型,
动作识别——帧为最小单位,视频流也是一个序列,因此也需要用序列模型来做。
这么看来,用序列模型,不仅仅可以做语音语言处理,CV相关的项目很多都可以做。
在这里插入图片描述
(sentiment classification:情感分类)

1.9 GRU:Gated Recurrent Unit

t a n h x ∈ ( − 1 , 1 ) tanhx\in(-1,1) tanhx(1,1)
在这里插入图片描述
s i g m o i d x ∈ ( 0 , 1 ) sigmoid x \in (0,1) sigmoidx(0,1)

  • Original : a t = g ( W a [ a t − 1 , x t + b a ) a^t =g(W_a[a^{t-1, x^{t}+b_a}) at=g(Wa[at1,xt+ba)
  • Simplified GRU:
    new variable:c(memory cell)
    in this version, c t = a t c^t = a^t ct=at (distinguished with LSTM)

    (1) In every step, a candidate for rewirting memory c t c^t ct:
    c ^ t = t a n h ( W c [ c t − 1 , x ] + b c ) \hat c^t=tanh(W_c[c^{t-1},x]+b_c) c^t=tanh(Wc[ct1,x]+bc),
    (2) Update Gate: decides to rewirte c t c^t ct or not (In lots of graph illustrations, denoted as a red/blue sigmoid-like curve)
    Γ u ∈ ( 0 , 1 ) = s i g m o i d ( W u [ c t − 1 , x t ] + b u ) \Gamma_u\in(0,1)=sigmoid(W_u[c^{t-1},x^t]+b_u) Γu(0,1)=sigmoid(Wu[ct1,xt]+bu)
    (3) then: new memory cell, when gate=1, rewite it with the candidate c ^ t \hat c^t c^t, otherwies let c t c^t ct the same
    c t = Γ u c ^ t + ( 1 − Γ u ) c ( t − 1 ) c^t=\Gamma_u \hat c^t+(1-\Gamma_u) c^{(t-1)} ct=Γuc^t+(1Γu)c(t1)
    ——when the memory is not needed anymore, it would be rewrited;(for example, with “cat”, write “is”, or with “cats”, write “are”, then we don’t need to remember it’s “cat” or “cats”, thus we can clear or rewirte then memory cell. )
    在这里插入图片描述

在这里插入图片描述

  • FULL GRU
    (1) There is one more gate: Relevance Gate
    which tell how relevant is c t − 1 c^{t-1} ct1 to computing c t c^t ct
    在这里插入图片描述
    (2) why do this?
    Because researchers over many years have tried lots of different versions, and find this one, GRU, robust and useful.

    3.10 LSTM(long short-term Memory)

    (memory is short-term, but in LSTM, this short-term memory is relatively longer)
    事实上LSTM比GRU早出来而且更强一点;GRU可以看作是LSTM的简化版,更快但是稍弱,如分离卷积之于普通卷积。 一般用LSTM

  • Formulations
    在这里插入图片描述

  • picture from blog post to Chris Ola: Understanding LSTM Networkpicture from blog post to Chris Ola

  • Peephole Connection(偷窥孔连接)
    LSTM的一种变种技术,把 c t − 1 c^{t-1} ct1加入到了三个gate的计算中
    在这里插入图片描述

1.11 Bidirectional RNN

Bidirectional RNN can look both forward and backward which enhance itds processing ability
在这里插入图片描述

  • 重点
    在这里插入图片描述
  • 这个图不如李宏毅的清晰,自己画一个如下
    在这里插入图片描述
  • 缺点: You do need the entire sequence; 那么在实时的语音识别里就用不了,因为需要等一个人说完整句话才能识别
  • NLP通常用Bidirectional LSTM
1.12 Deep RNN

三层的RNN已经算比较深了
除非是y这个地方换成了只有纵向而没有水平连接的深层网络
下图是一个三层RNN(纵向)
在这里插入图片描述


二、NLP

2.1 Word repersentation 词汇表征——将维/词汇联系

1、Word embedding(词嵌入):让算法自动理解词汇,man to women, king to queen

2、之前都是用字典与one-hot来编码 词汇的
这样词汇是孤立的
它不懂 man to women, king to queen,
同时也有维度很大的缺点

3、所以使用词嵌入:featurized representation

这样orange与apple就很接近,如果模型看过“I want a glass of orange juice", 那么它在做填空的时候就知道“I want a glas of apple ____“可以填”juice”

4、为什么叫embedding:
比如10000个词汇,用了300个feature,那么这10000个词汇全部被映射成一个feature为坐标轴的300维的空间中的一个个点,相当于嵌入到了一个超立方体中。
也成功降维了:10000——>300
在这里插入图片描述

图中是利用t-SNE算法将300D的空间投影到2D空间看下关系(但是实际上投影到2D后大概率看不出关系的)

在这里插入图片描述


2.2 Using Word Embedding (In NLP)

1、小数据集怎么整
在这里插入图片描述
假设小数据集里没有“durian"”cultivator"(榴莲培育家),怎么无米之炊?
——可以用从网上下载大数据集的Embedding表示——迁移学习


2.3 Properties of word embeddings

word embeddings可以实现analogy reasoning(类比推理) ,而analogy reasoning也可以帮助大家理解word embedding在干什么
在这里插入图片描述

在这里插入图片描述
问:man对woman,king对what?
答:因为 e m a n − e w o m a n ≈ e k i n g − e q u e e n e_{man}-e_{woman}\approx e_{king}-e_{queen} emanewomanekingequeen,所以类比推理:man对woman, king对queen。 做法是在所有embedding中寻找与 e k i n g − e m a n − e w o m a n e_{king}-{e_{man}-e_{woman}} ekingemanewoman最接近的embedding vector,发现是queen的vector,所以答案是queeen
1、Fomulation:
w = arg max ⁡ e w s i m ( e w , e k i n g − e m a n + e w o m a n ) ) w = \argmax_{e_w} \rm{sim}(e_w,e_{king}-e_{man}+e_{woman})) w=ewargmaxsim(ew,ekingeman+ewoman))
2、sim()

s i m ( u , v ) = u T v ∣ ∣ u ∣ ∣ 2 ∣ ∣ v ∣ ∣ 2 \rm{sim}(u,v)=\frac{u^Tv}{||u||_2||v||_2} sim(u,v)=u2v2uTv(即归一化的内积或者说 c o s θ \rm{cos}\theta cosθ ∣ ∣ u ∣ ∣ 2 ∣ ∣ v ∣ ∣ 2 c o s θ = u ⃗ T v ⃗ ||u||_2||v||_2\rm{cos}\theta=\vec{u}^T\vec{v} u2v2cosθ=u Tv )

夹角0度,平行向量,sim为最大值1:
夹角越大,越不平行(not what we want),sim越小。
在这里插入图片描述

s i m = ∣ ∣ a − b ∣ ∣ 2 \rm{sim}=||a-b||^2 sim=ab2


2.4 Embedding matrix

ds

O i O_i Oi表示第i个元素为1,其他元素为0的one-hot vector,即第i个词汇的one-hot表示;
e i e_i ei表示Embedding matrix第i个Embedding column(vector),即第i个词汇的word embedding vector.
E E E为Embedding matrix
e i = E ⋅ O i e_i = E \cdot O_i ei=EOi
(公式上是这么表示,但是实际上就是python取第i个列切片的事)


2.5 Language modeling problem

一开始的算法比较复杂;后来越来越简单,结果很不错(炼丹了炼丹了)
下面先讲讲复杂的再讲讲简单的
1、固定窗口长度(比如4)(左/右or both )以处理固定长度序列;CNN举例
在这里插入图片描述

2、更简单的算法Skip-Gram: Neaby 1 word (instead of 4)
glass——>juice
(看2.6节的formulation)


2.6 Word2Vec模型——如何学习/得到Embedding matrix

1、Model1——Skip-grams——Context&Target对;利用监督学习来学习embedding
在这里插入图片描述

实际上是算 给定中心词汇,算出非中心词汇或者说目标词汇是某个词的概率

t means target or y
E E E是Embedding matrix,同时也是我学习的参数
θ t \theta_t θt是softmax的参数

在这里插入图片描述
2、softmax classification存在的问题——因为词库大,计算太太太慢

  • 解决方法1:hierarchical softmax (分级softmax分类,树形)
    不一定非是平衡树,可以思想上像huffman按常用频率决定某个类别在树上的深度
    在这里插入图片描述
  • 解决方法2:见2.7负采样

3、如何sample/决定 contex c ?
the/of/a巨高频
orange/durian不高频
训练这些不高频的,收益才高
(比如天天花5小时只学习1+1这些没营养的巨简单的,小朋友没有提高,考试只能得10分;
花时间学习了方程式,小朋友进阶了,模型变聪明了,考了90分)
4、model2——CBOW
continuous bag of words(连续词袋模型),用左右两边的词汇来做输入预测


2.7 负采样 Negative sampling——高效的方案——化为多个二分类问题

在这里插入图片描述
这也是原始skip-gram等模型下softmax的高效解决方案
在这里插入图片描述
如何选择negative examples?
如果根据出现频率——会取到the/of/and…
如果均匀随机取样——词汇间毫无关系
解决方案——经验之谈——在这里插入图片描述


2.8 GloVe模型(Global vectors for word represnetation)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值