论文笔记:A Structured Self-Attentive Sentence Embedding
A Structured Self-Attentive Sentence Embedding
ICLR 2017
2018-08-19 14:07:29
Paper:https://arxiv.org/pdf/1703.03130.pdf
Code(PyTorch): https://github.com/kaushalshetty/Structured-Self-Attention
Video Tutorial (Youtube): Ivan Bilan: Understanding and Applying Self-Attention for NLP | PyData Berlin 2018
Blog:
1. 机器之心
2. https://www.paperweekly.site/papers/notes/148
Related Papers: Self-Attention Generative Adversarial Networks
Background and Motivation:
现有的处理文本的常规流程第一步就是:Word embedding。也有一些 embedding 的方法是考虑了 phrase 和 sentences 的。这些方法大致可以分为两种: universal sentence(general 的句子)和 certain task(特定的任务);常规的做法:利用 RNN 最后一个隐层的状态,或者 RNN hidden states 的 max or average pooling 或者 convolved n-grams. 也有一些工作考虑到 解析和依赖树(parse and dependence trees);
对于一些工作,人们开始考虑通过引入额外的信息,用 attention 的思路,以辅助 sentence embedding。但是对于某些任务,如:情感分类,并不能直接使用这种方法,因为并没有此类额外的信息:the model is only given one single sentence as input. 此时,最常用的做法就是 max pooling or averaging 所有的 RNN 时间步骤的隐层状态,或者只提取最后一个时刻的状态作为最终的 embedding。
而本文提出一种 self-attention 的机制来替换掉通常使用的 max pooling or averaging step. 因为作者认为:carrying the semantics along all time steps of a recurrent model is relatively hard and not necessary. 不同于前人的方法,本文所提出的 self-attention mechanism 允许提取句子的不同方便的信息,来构成多个向量的表示(allows extracting different aspects of the sentence into multiple vector representation)。在我们的句子映射模型中,是在 LSTM 的顶端执行的。这确保了 attention 模型可以应用于没有额外信息输入的任务当中,并且减少了 lstm 的一些长期记忆负担。另外一个好处是,可视化提取的 embedding 变的非常简单和直观。
Approach Details:
1. Model
所提出的 sentence embedding model 包含两个部分:(1)双向 lstm;(2)the self-attention mechanism;
给定一个句子,我们首先将其进行 Word embedding,得到:S = (w1, w2, ... , wn),然后讲这些 vector 拼成一个 2-D 的矩阵,维度为:n*d;
然后为了 model 不同单词之间的关系,我们利用双向 lstm 来建模,得到其两个方向的隐层状态,然后,此时我们可以得到维度为:n*2u 的矩阵,记为:H。
为了将变长的句子,编码为固定长度的 embedding。我们想通过选择 n 个 LSTM hidden states 的线性组合,来达到这一目标。计算这样的线性组合,需要利用 self-attention 机制,该机制将 lstm 的所有隐层状态 H 作为输入,并且输出为一个向量权重 a:
其中,$W_{s1}$ 是大小为 $d_a * 2u$ 的权重矩阵,$w_{s2}$ 是大小为 $d_a$ 的向量参数,这里的 $d_a$ 是我们可以自己设定的。由于 H 的大小为:n * 2u, annotation vector a 大小为 n,the softmax()函数确保了计算的权重加和为1. 然后我们将 lstm 的隐层状态 H 和 attention weight a 进行加权,即可得到 attend 之后的向量 m。
向量的表示通常聚焦于句子的特定成分,像一个特定的相关单词或者词汇的集合。所以,我们需要反映出不同的语义的成分和放慢。但是,一个句子中可能有多个不同的成分,特别是长句子。所以,为了表示句子的总体的语义,我们需要多个 m's 来聚焦于不同的部分。所以,我们需要用到:multiple hops of attention. 即:我们想从句子中提取出 r 个不同的部分,我们将 $w_s2$ 拓展为:$r * d_a$ 的 matrix,记为:$W_{s2}$,然后 the resulting annotation vector a 变为了 annotation matrix A. 正式的来说:
此处,softmax()是沿着输入的 第二个维度执行的。我们可以将公式(6)看做是一个 2-layer MLP without bias。
映射向量 m 然后就变成了:$r * 2u$ 的 embedding matrix M。我们通过将 annotation A 和 lstm 的隐层状态 H 进行相乘,得到 the r weighted sums,结果矩阵就是句子的映射:
M = AH
2. Penalization Term
当 attention 机制总是提供类似的 summation weights for all the r hops,映射矩阵 M 可能会受到冗余问题的影响。然后,我们需要一个惩罚项,来估计 summation weight vectors 变的 diverse。
最好的衡量的两个 summation weight vectors 之间的度量方式就是:KL Divergence(Kullback Leibler Divergence),然而,作者发现在这个问题中,并不适合。作者猜想这是由于:we are maximizing a set of KL divergence, we are optimizing the annotation matrix A to have a lot of sufficiently small or even zero values at different softmax output units, and these vast amount of zeros is making the training unstable. 另一个 KL 不具有的特征,但是我们缺需要的是:we want to each individual row to focus on a single aspect of semantics, so we want the probabilty mass in the annotation softmax output to be more focused.
我们将 A 乘以其转置,然后减去单位矩阵,作为其冗余度的度量:
Experiments:
==
论文笔记:A Structured Self-Attentive Sentence Embedding的更多相关文章
- 《A Structured Self-Attentive Sentence Embedding》(注意力机制)
Background and Motivation: 现有的处理文本的常规流程第一步就是:Word embedding.也有一些 embedding 的方法是考虑了 phrase 和 sentence ...
- 将句子表示为向量(下):基于监督学习的句子表示学习(sentence embedding)
1. 引言 上一篇介绍了如何用无监督方法来训练sentence embedding,本文将介绍如何利用监督学习训练句子编码器从而获取sentence embedding,包括利用释义数据库PPDB.自 ...
- 将句子表示为向量(上):无监督句子表示学习(sentence embedding)
1. 引言 word embedding技术如word2vec,glove等已经广泛应用于NLP,极大地推动了NLP的发展.既然词可以embedding,句子也应该可以(其实,万物皆可embeddin ...
- Deep Learning论文笔记之(八)Deep Learning最新综述
Deep Learning论文笔记之(八)Deep Learning最新综述 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些论文,但老感觉看完 ...
- 论文笔记之:Natural Language Object Retrieval
论文笔记之:Natural Language Object Retrieval 2017-07-10 16:50:43 本文旨在通过给定的文本描述,在图像中去实现物体的定位和识别.大致流程图如下 ...
- 【论文笔记】Learning Fashion Compatibility with Bidirectional LSTMs
论文:<Learning Fashion Compatibility with Bidirectional LSTMs> 论文地址:https://arxiv.org/abs/1707.0 ...
- Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现(转)
Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些论文, ...
- 论文笔记之:Visual Tracking with Fully Convolutional Networks
论文笔记之:Visual Tracking with Fully Convolutional Networks ICCV 2015 CUHK 本文利用 FCN 来做跟踪问题,但开篇就提到并非将其看做 ...
- Twitter 新一代流处理利器——Heron 论文笔记之Heron架构
Twitter 新一代流处理利器--Heron 论文笔记之Heron架构 标签(空格分隔): Streaming-process realtime-process Heron Architecture ...
随机推荐
- centos7 与 archlinux用户 安装 python3模块 pytaglib
对于 centos7用户: yum group install "Development Tools" yum install taglib-devel yum install p ...
- date格式互转
+"%Y/%m/%d-%H:%M:%S" date -d "2017/11/21 17:02:09" +%s
- WPS生成文章目录
WPS生成文章目录 1.引用–>插入目录...即可!
- 编译安装centos6.9 php7.0 mysql5.6 nginx1.8
2018年3月15日 11:41:40 注意文章时效! 此文章不是给新用户参考的,没有每一步的操作,请注意! yum -y groupinstall "Development Tools&q ...
- :after和:before 伪类
1 使用伪类画三角形 .div{ margin-top: 100px; margin-left: 100px; } .div:after{ content: ''; display:inline-bl ...
- ext 的controller中的refs的使用方法
通过ext api 可以知道ext 的controller中有个refs的属性,对于这个属性 文档上是这么说的:配置数组构建页面上的视图的引用. 我并看不懂,接下来说的是我对这个refs的理解. 对这 ...
- android 前台服务不显示通知
原因可以在哪里写了执行完成后就自动结束的吧 导致前台服务没有出现 如我 @Override public int onStartCommand(Intent intent, int flags, in ...
- a标签和p标签不能设置margin
经常会发现正常div的属性在a标签上或者p标签上都不管用,这是因为a标签和p标签都不是盒子模型. 例如: <div style="margin-top:5px;">&l ...
- ZooKeeper是什么
ZooKeeper概念 相信大家对 ZooKeeper 应该不算陌生,但是你真的了解 ZooKeeper 是什么吗?如果别人/面试官让你讲讲 ZooKeeper 是什么,你能回答到哪个地步呢? 本人曾 ...
- Eclipse Error Reporting Welcome to the Eclipse Error Reporting Service.Do you want to help Eclipse? Enable Disable
在开发的时候,使用Eclipse IDE,提示如下信息, 这是Eclipse的错误报告,如果不想发送,可以关闭掉,关闭方法: 选择Preferences -> General -> Err ...