本文是ACL2018上的文章,主要研究对话领域选择回复的问题,作者提出了DAM模型,主要通过stacked self-attention获取不同维度的表征,从而得到self-attention matching matrix和cross-attention matching matrix,取得了不错的效果。
paper link
code link
Introduction
本文研究的问题是response selection:给定一段对话历史和一些候选回复,从中选择最佳答案。
人类生成回复通常依赖于语义和功能依赖,例如对话历史和回复之间的指代关系。本文提出了Deep Attention Matching Network (DAM),完全基于attention来获得候选回复与对话历史之间的依赖信息(dependency information),进而得到匹配回复。DAM借鉴于Transformer,主要使用了两种attention:
- 使用堆叠的自注意力层来获取不同粒度(维度)上的文本片段的表征
- 使用context和response计算cross attention得到文本段间的关系
Figure 1: Example of human conversation on Ubuntu system troubleshooting. Speaker A is seeking for a solution of package management in his/her system and speaker B recommend using, the debian package manager, dpkg. But speaker A does not know dpkg, and asks a backchannel-question (Stolcke et al., 2000), i.e., “no clue what do you need it for?”, aiming to double-check if dpkg could solve his/her problem. Text segments with underlines in the same color across context and response can be seen as matched pairs.
作者认为matched segment pairs对于回复选择来说很重要,可以分为以下两种层次:
- 浅层的文本相关性:例如词汇间的重叠
package
packages
- 语义上的相关(latent dependency):例如
it
指代dpkg
本文的贡献在于:DAM完全使用注意力机制来建模context和candidate response之间的联系,避免了之前一些基于RNN的方法带来的高代价的计算消耗,并且取得了SOTA的结果(本文发表于ACL2018,之后在DSTC7的评测中阿里达摩院的一篇文章Sequential Attention-based Network for Noetic End-to-End Response Selection超过该结果),充分证明了self-attention和cross-attention的有效性。
Deep Attention Matching Network
Problem Formalization
给定对话历史 c={u0,…,un−1},ui 代表utterance,r 代表一个候选回复,y∈{0,1} 是一个二类标签,表示r是不是c的一个合适回复。目标为学习一个匹配模型 g(c,r) ,衡量c与r之间的相关性。
Model Overview
Figure 2: Overview of Deep Attention Matching Network
对于context中的每一个utterance ui=[wui,k]nui−1k=0,nui 代表 ui中words的数量,一个候选回复 r=[wr,t]nr−1t=0,nr 代表 r中words的数量。ui,r共享相同的词向量,分别得到两个词向量的序列 U0i=[e0ui,0,…,e0ui,nui−1] 和 R0=[e0r,0,…,e0r,nr−1],其中e是一个d维的词向量。接下来针对于ui和r构建不同粒度的表征,具体是用L个相同的self-attention层,得到[Uli]Ll=0和[Rl]Ll=0。之后对于不同的粒度l∈[0,L],分别计算两个相似度矩阵Mui,r,lself,Mui,r,lcross,分别衡量textual information和dependency information。最后将这些矩阵合并成三维的立方体,通过三维卷积和池化得到一维向量,经过单层全连接得到匹配分数。
Attentive Module
类似于Transformer结构,但是没有使用multi-head和position-encoding。
Representation
给定utterance ui 和 response r 的词向量序列U0i,R0,DAM模型将其作为Attentive Module的输入,并且堆叠多个Module:
其中l∈[0,L],代表不同的粒度。
Matching
得到[Uli]Ll=0和[Rl]Ll=0之后,在不同的粒度上计算segment-segment匹配矩阵:
上式代表Uli[k]和Rl[t]的内积,也即Ui中第k个embedding与Rl[t]第t个embedding做内积,这代表浅层的文本相关性。
另一种cross-attention-matrix定义为:
作者认为这代表语义相关性。
Aggregation
DAM模型将这些Mui,r,lself,Mui,r,lcross矩阵拼接起来(l∈[0,L],共2(L+1)个),得到Q:
上式中n=2(L+1),对应每个channel上的元素为:
之后经过conv_3d和pooling_3d得到特征向量fmatch(c,r),再经过一层感知器:
DAM的损失函数为负极大似然函数。
Experiment
Table 1: Experimental results of DAM and other comparison approaches on Ubuntu Corpus V1 and Douban Conversation Corpus.
其中SMNdynamic是基于RNN的模型,DAMfirst和DAMlast分别指仅利用stacked self-attention的第一层和最后一层,DAMself和DAMcross分别代表仅仅利用一种attention matching matrix。
Analysis
作者分析了不同的对话历史轮次对于选择回复的影响:
Figure 4: DAM’s performance on Ubuntu Corpus across different contexts. The left part shows the performance in
different utterance number of context. The right part shows performance in different average utterance text length of context as well as self-attention stack depth.
从中有以下结论:
- 对于不同的对话轮次,DAM都有着不错的改善,证明了使用多粒度信息表征的稳定性。
- 对于utterance比较短的对话,DAM的效果会比较差,这说明短文本对话中含有的信息可能会比较少;同时,stacked self-attention的层数也有助于改善准确率。
作者也指出了DAM的不足之处:
- fuzzy-candidate, where response candidates are basically proper for the conversation context, except for a few improper details.
- logical-error, where response candidates are wrong due to logical mismatch, for example, given a conversation
context A: “I just want to stay at home tomorrow.”, B: “Why not go hiking? I can go with you.”, response candidate like “Sure, I was planning to go out tomorrow.” is logically wrong because it is contradictory to the first utterance of speaker.