主要内容:
- 为什么要使用CNN
- single layer connection
- pooling: max-pooling
- Multiple-Filters: multiple n-grams
- Multiple-Channels: 两个词向量 static, dynamic
- lassification after one CNN layer
为什么要使用CNN?
CNN模型在计算机视觉与语音识别方面取得了卓越的成就. 在 NLP 也是可以的. 卷积具有局部特征提取的功能, 所以可用 CNN 来提取句子中类似 n-gram 的关键信息.
Single layer connection
Convolution Neural Networks for Sentence Classification

- 对于单个词,其词向量:\(x_i\in R^k\), k维词向量
- n个词concatenate在一起表示为:\(x_{1:n}=x_1\bigoplus x_2 \bigoplus...\bigoplus x_n\)
- 卷积过滤器filter: \(w\in R^{hk}\) h表示过滤器的尺寸,也就是覆盖多少个词.
上图figure13表示: k=2,n=5,h=3
需要注意的是filter是一个长度为 hk 的 vector,与input的每一个时间步做一次卷积(加权和)得到一个实数: \[c_i=f(W^Tx_{i:i|h-1}+b)\] 那么输出向量:\(c=[c_1,c_2,...,c_{n-h+1}]\in R^{n-h+1}\)
如果h=3,那么最后两个词 my birth 就不够卷积,可以如图figure14所示采用 h-1 zero-vector padding.
pooling
max-pooling: \[\hat c=max\{c\}, c\in R\]
filter可以看做和图像中的filter一样,一个图像特征提取器,那么在文本中,一个filter也可以看做是一个n-gram特征提取器,比如一个用来表示positive bigram,那么这个filter和句子中同样表示positive bigram做卷积的话,其值就会很大~那么使用max-pooling就是找到这个值
当然使用min-pooling也是可以的.但更多的时候我们选择用 relu作为激活函数,那么使用min-pooling的话,就会出现更多的 0.
Multiple-Filters
We can use multiple bi-gram filters because each filter will learn to recognize a different kind of bi-gram. Even more generally, we are not restricted to using just bi-grams, we can also have filters using tri-grams, quad-grams and even higher lengths. Each filter has an associated max-pool layer. Thus, our final output from the CNN layers will be a vector having length equal to the number of filters.
同时使用好几个bigram,用以获取不同的pattern. 除了bigram,还会使用trigram,unigram等等。
Multiple-Channels
我们有时候会需要在特定的场景下更新词向量,也就是也训练词向量参数,这样能够适应更特殊的任务。但如果在test中出现了train中没有出现的词unseen word, 那么这个词的词向量还会保持初始词向量的值(Glove等)。但是与这个词语义相关的词的词向量却发生了变化,这样就造成了相似的词的的词向量相差较大。这显然是不合理的。
所以我们使用两个词向量,one ’static’ (no gradient flow into them) and one ’dynamic’, which are updated via SGD.
- Backprop into only one set, keep other "static"
- Both channels are added to \(c_i\) before max-pooling.
Classification after one CNN layer
- First one convolution, followed by one max-pooling
- To obtain final feature vector: \(z=[\hat c_1,...,\hat c_m]\) 假设有m个过滤器filter
- Simple final softmax layer \(y=softmax(W^{(S)}z+b)\)
Convolution Neural Networks for Sentence Classification 论文中的模型:

- 第一层: two word-vector channels \(n\times k\times 2\)
- 第二层: m个filter得到的m列feature maps,由于有多种filter尺寸,如果没有zero-padding的话,那么得到的feature maps长度是不一致的。
- 第三层:max-pooling \(z=[\hat c_1,...,\hat c_m]\)
- 第四层:fully connectioned layer with dropout and softmax output.
Tricks: Dropout
\[y=softmax(W^{(S)}(r\circ z)+b)\]
针对dropout,在train和test时,处理方式是不一样的:
模型参数选择问题
CNN更容易实现在GPU上的并行处理。


CNN的变种以及应用

Narrow vs Wide
- Narrow就是没有zero-padding: 那么output长度就是 \(n-h+1\)
- Wide就是前后两端都有h-1 zero-padding: 那么output长度就是: \([n+2\times (h-1)]- h+1=n+h-1\)


k-max pooling 相比max-pooling, k-max pooling是选出最大的k个值
模型对比总结

Presentation
Character-Aware neural language models,Yon Kim at al.
