DGCNN

Architecture Overview 

Overall architecture model from WebQA reference papers  Dataset and Sequence Labeling Recurrent Neural Model for Open-Domain Factoid Question  [2]. This paper has several features:

1. After LSTM problem directly obtained by coding "to encoding", and then spliced ​​to each word vector material

2. The manual extraction of the two co-occurrence characteristics

3. The final prediction converted to a sequence labeling tasks with CRF solve

 

The DGCNN basically designed Along the way, except that :

1. All LSTM part of the original models are replaced with CNN

2. Extract a richer feature co-occurrence (8)

3. Remove of CRF, to "0/1 mark" to separate the start and end position of the identification answer, it can be seen as a kind of "semi-half pointer labeled" structure

 

Convolution structure

In this section we used to parse figure Conv1D Block

Door mechanism

The convolutional model used in the structure, Convolutional Sequence from the FaceBook to Sequence Learning [3], and in the "share a slide: Fancy Natural Language Processing" [4] is also mentioned in an article.

 

Suppose we are dealing with vector sequence is X = [x1, x2, ..., xn], then we can add to the normal door one-dimensional convolution:

 

Note that here the same (such as the number of the convolution kernel, the window size is the same) Conv1D two forms, weights are not shared , that is doubled parameters, wherein activated with a sigmoid function, without a further activation function then multiplies them bit by bit.

Because the range of the sigmoid function is (0,1), so Intuitively, for each output is added Conv1D have a "valve" to control the flow. This is GCNN structure, or the structure may be such as to activate a function, called GLU (Gated Linear Unit).

In addition to the intuitive sense, but with a GCNN advantage is that it almost need not worry about the disappearance of the gradient problem, because there is a convolution without any activation function, so this part of the derivative is a constant (multiplied by the door ), it can be said the probability is very small gradient disappears. If the size of the input and output of the same dimensions, then we'll enter inside also added that the use of residual structure: 

 

It is worth mentioning that we use residual structure, not only to solve the gradient disappears, but so that the information can be transmitted in a multi-channel . We can rewrite the equation more visual equivalent form, so that we can more clearly see how the information is flowing: 

 

From (3) where we can more clearly see the flow of information: the probability 1-σ directly through to the probability of σ through transformation after the pass. This form is very much like GRU recurrent neural network model.

Supplementary derivation: 

 

Since Conv1D1 activation function is not added, it is just a linear transformation, whereby Conv1D1 (X) -X may be bonded together, is equivalent to a single Conv1D1. To put it plainly, in the training process, Conv1D1 (X) -X can do things, Conv1D1 (X) can be done. Such that (2) and (3) they are equivalent.

 

Expansion convolution

Next, in order to make CNN model can capture more distant, and they will not increase the model parameters, we use the expansion of convolution .

Normal contrast expansion convolution convolution with, you can use a map to demonstrate:  

The same three-layer neural network convolution (The first layer is the input layer), a window size of 3. Ordinary convolution in the third layer, each node can only be captured before and after the three inputs , while with the other input completely detached. 

膨胀卷积在第三层时则能够捕捉到前后 7 个输入,但参数量和速度都没有变化。这是因为在第二层卷积时,膨胀卷积跳过与中心直接相邻的输入,直接捕捉中心和次相邻的输入(膨胀率为 2),也可以看成是一个“窗口大小为 5 的、但被挖空了两个格的卷积”,所以膨胀卷积也叫空洞卷积(Atrous Convolution)

在第三层卷积时,则连续跳过了三个输入(膨胀率为 4),也可以看成一个“窗口大小为 9、但被挖空了 6 个格的卷积”。而如果在相关的输入输出连一条线,就会发现第三层的任意一个节点,跟前后 7 个原始输入都有联系。

按照“尽量不重不漏”的原则,膨胀卷积的卷积率一般是按照 1、2、4、8、...这样的几何级数增长。当然,这里指明了是“尽量”,因为还是有些重复的。这个比例参考了 Google 的 wavenet 模型。

 

Block

现在就可以解释模型图中的各个 Conv1D Block 了,如果输入跟输出维度大小一致时,那么就是膨胀卷积版的 (3) 式;如果输出跟输出维度大小不一致时,就是简单的 (1) 式,窗口大小和膨胀率在图上都已经注明。

 

注意力

从模型示意图可以看到,本文的 DGCNN 模型中,Attention 主要用于取代简单的 Pooling 来完成对序列信息的整合,包括将问题的向量序列编码为一个总的问题向量,将材料的序列编码为一个总的材料向量。

这里使用的 Attention 稍微不同于 Attention is All You Need 中的 Attention,本文这种 Attention 可以认为是一种“加性注意力”,形式为:

 

这里的 v,W 都为可训练参数。而 Act 为激活函数,一般会取 tanh,也可以考虑 swish 函数。注意用 swish 时,最好把偏置项也加上去,变为: 

 

这种 Attention 的方案参考自 R-Net 模型(注:不一定是 R-Net 首创,只是我是从 R-Net 中学来的)。

 

位置向量

为了增强 CNN 的位置感,我们还补充了位置向量,拼接到材料的每个词向量中。位置向量的构造方法直接沿用 Attention is All You Need 中的方案: 

 

输出设计

这部分是我们整个模型中颇具特色的地方。

 

思路分析

到现在,模型的整体结构应该已经呈现出来了。首先我们通过卷积和注意力把问题编码为一个固定的向量,这个向量拼接到材料的每个词向量中,并且还拼接了位置向量、人工特征。

这时候我们得到了一个混合了问题、材料信息的特征序列,直接对这个序列进行处理即可,所以后面接了几层卷积进行编码处理,然后直接对序列进行标注,而不需要再对问题进行交互了。 

在 SQUAD 的评测中,材料是肯定有答案的,并且答案所在的位置也做好了标注,所以 SQUAD 的模型一般是对整个序列做两次 softmax,来预测答案的开始位置和终止位置,我们一般称之为“指针网络”。

然而在 WebQA 式问答,材料中不一定有答案,所以我们不用 softmax,而是对整个序列都用 sigmoid,这样既允许了材料中没有答案,也允许答案在材料中多次出现。 

 

双标注输出

既然用到标注,那么理论上最简单的方案是输出一个 0/1 序列:直接标注出材料中的每个词“是(1)”或“否(0)”答案。

然而,这样的效果并不好,因为一个答案可能由连续多个不同的词组成,要让模型将这些不同的词都有同样的标注结果,有可能“强模型所难”。于是我们还是用两次标注的方式,来分别标注答案的开始位置和终止位置

这样一来,模型的输出设计跟指针方式和纯序列标注都不一样,或者说是两者的简化及融合。 

这个全局打分对模型的收敛和效果具有重要的意义,它的作用是更好地判断材料中是否存在答案,一旦材料中没有答案,直接让即可,不用“煞费苦心”让每个词的标注都为 0。

 

人工特征

文章的前面部分,我们已经多次提到过人工特征,那么这些人工特征的作用有多大呢?简单目测的话,这几个人工特征对于模型效果的提升可能超过 2%。可见设计好的特征对模型效果的特征、模型复杂度的降低,都有着重要的作用。 

 

Q-E全匹配

也就是判断材料中的词是否在问题出现过,出现过则为 1,没出现过则为 0。这个特征的思路是直接告诉模型问题中的词在材料中什么地方出现了,那些地方附近就很有可能有答案。这跟我们人类做阅读理解的思路是吻合的。 

 

E-E共现

这个特征是计算某个材料中的词在其他材料中的出现比例。比如有 10 段材料,第一段材料有一个词 w,在其余九段材料中,有 4 段都包含了这个词,那么第一段材料的词 w 就获得一个人工特征 4/10。 这个特征的思路是一个词出现在的材料越多,这个词越有可能是答案。 

 

Q-E软匹配

以问题大小为窗口来对材料的每个窗口算 Jaccard 相似度、相对编辑距离。 

比如问题“白云山 的 海拔 是 多少 ?”,材料“白云山 坐落 在 广州 , 主峰 海拔 3 8 2 米”。问题有 6 个词,那么窗口大小就为 6,将材料拆分为: 

其中 X 代表占位符。有了这个拆分,我就可以算每一块与问题的 Jaccard 相似度了,将相似度的结果作为当前词(也就是红色词)的一个特征,上述例子算得 [0.13, 0.11, 0.1, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.1, 0]。 

同样地,我们还可以算每一块与问题的编辑距离,然后除以窗口大小,就得到一个 0~1 之间的数,我称之为“相对编辑距离”,上述例子算得 [0.83, 0.83, 0.83, 0.83, 1, 1, 1, 0.83, 1, 1, 1]。 

Jaccard 相似度是无序的,而编辑距离是有序的,因此这两个做法相对于从有序和无序两个角度来衡量问题和材料之间的相似度。这两个特征的思路跟第一个特征一样,都是告诉模型材料中哪部分会跟问题相似,那部分的附近就有可能有答案。 

 

模型设置

下面是实现模型的一些基本要点。 

 

中文分词

从前面的介绍中可以看到,本模型是基于词来实现的,并且基于前面说的人工特征简单引入了字符级别的信息。不过,为了使得模型整体上更加灵活,能够应答更多的问题,本文仅仅对输入进行了一个基本的分词,使得分词的颗粒度尽量低一些。

具体实现为:自己写了一个基于一元模型的分词模块,自行准备了一个约 50 万词的词典,而所有的英文、数字都被拆开为单个的字母和数字,比如 apple 就变成了五个“词”:a p p l e,382 就变成了三个“词”:3 8 2。 

由于没有新词发现功能,这样一来,整个词表的词就不会超过 50 万。事实上,我们最后得到的模型,模型总词数只有 30 万左右。

当然,读者可以使用结巴分词,关闭结巴分词的新词发现,并且手动对数字和英文进行拆分,效果是一样的。

 

部分参数

1. 词向量的维度为 128 维,由比赛方提供的训练语料、WebQA 语料、50 万百度百科条目、100 万百科知道问题用 Word2Vec 预训练而成,其中 Word2Vec 的模型为 Skip Gram,窗口为 5,负采样数为 8,迭代次数为 8,训练时间约为 12 小时;

2. 词向量在 DGCNN 模型的训练过程中保持固定; 

3. 所有 Conv1D 的输出维度皆为 128 维,位置向量也是 128 维; 

4. Conv1D 的最大长度取为 100,如果一个 batch 中某些样本涉及到 padding,那么对 padding 部分要做好 mask;

5. 由于最后变成一个二分类的标注形式,并且考虑到正负类不均衡,使用二分类的 focal loss 作为损失函数;

6. 用 adam 优化器进行训练,先用的学习率训练到最优(大概 6 个 epoch 内),然后加载最优模型,改用学习率训练到最优(3 个 epoch 内)。

 

正则项

在比赛后期,我们发现一种类似 DropPath 的正则化能轻微提升效果,不过提升幅度我也不大确定,总之当时是带来了一定的提升。

这个正则化手段建立在 (3) 式的基础上,我们的思路是在训练阶段对“门”进行扰动: 

 

其中 ε 是 [−0.1,0.1] 内的均匀随机数张量。这样一来,我们给 GCNN 的“门”加入了“乘性噪声”来使得具有更好的鲁棒性(对抗参数的小扰动)。

这个正则化方案的提出,多多少少受到了 FractalNet: Ultra-Deep Neural Networks without Residuals [5] 和 Shake-Shake regularization [6] 里边的正则化技术启发。

 

解码策略

打分方式

何为答案解码?不管是用 softmax 形式的指针,还是用本文的 sigmoid 形式的“半指针-半标注”,最后模型输出的是两列浮点数,分别代表了答案起始位置和终止位置的打分。

但问题是,用什么指标确定答案区间呢?一般的做法是:确定答案的最大长度 max_words(我取了 10,但汉字算一个,字母和数字只算半个),然后遍历材料所有长度不超过 max_words 的区间,计算它们起始位置和终止位置的打分的和或积,然后取最大值

 

参考:https://mp.weixin.qq.com/s/eAphGLNM2FZhIJmtsS0kpg

 

Guess you like

Origin www.cnblogs.com/callyblog/p/11111493.html