【深度学习在NLP中应用一】文本摘要(Text Summarization)和句子压缩(Sentence Compression)

本文系统梳理了四篇代表性论文,聚焦基于深度学习的文本摘要与句子压缩技术。涵盖RNN+Attention新闻标题生成、最小风险训练优化、AttSum联合检索与摘要建模,以及卷积编码+Attention的抽象式句子摘要。核心方法均基于Seq2Seq框架改进,强调Attention机制设计、训练目标优化(如ROUGE导向的MRT)、多任务联合学习及编码结构创新(CNN/RNN/GRU)。实验均在Gigaword、LCSTS、UDC等主流NLP数据集上验证有效性。

概述

该系列文章主要介绍深度学习在自然语言处理中的应用,具体会记录阅读论文中一些思考和论文关键点,该系列文章每周会持续更新。该文主要集中在文本摘要和句子压缩方面,针对这类问题主要思路就是在经典Seq2Seq基础上进行改写和改进。

Generating News HeadLines with RNN(2015)

模型概览

本文主要解决问题是使用RNN网络自动生成新闻标题,并且尝试两种Attention机制,发现简单的Attention也能得到很好效果。
这里写图片描述

  1. 编码阶段:输入一系列词语序列,先进行Embedding将词映射到稠密高维向量,然后放入到多层RNN网络结构中。
  2. 解码阶段,将编码阶段最后一个词语的输出状态作为解码阶段的输入,同时添加特殊标志位作为解码阶段的第一个输入。然后通过softmax层和Attention机制进行编码过程生成;当某时刻输入预测之后,该词将作为下一个预测结果的输入。
  3. 训练阶段技巧,一般情况会采用“teacher forcing”方式进行训练,即某时刻预测结果会作为下一时刻输入。然后这种训练方式的问题是在测试阶段没有标准答案,每次预测后都会随机采样作为标准答案。这样就造成了训练和测试阶段不一致,为解决该问题比较经典方法是,按照一定概率,例如10%,在训练阶段采用随机采样的结果作为下一时刻的输入。
  4. Attention机制,本文尝试了两种机制,第一种方案 即soft Attention,即某时刻输入的上下文是编码阶段所有词语的加权平均,加权系数度量的是当前解码阶段历史状态和编码输出状态内积的几何平均,计算如下αji(t)=exp(hiThj−1)∑kexp(hkThj−1)\alpha_{ji}(t)=\frac{exp(h_i^Th_{j-1})}{\sum_k exp(h_k^Th_{j-1})}αji​(t)=∑k​exp(hkT​hj−1​)exp(hiT​hj−1​)​其中αji\alpha_{ji}αji​表示解码阶段第j时刻和输入序列中第i个时刻的加权系数,h_i表示输入序列隐藏状态,h_j表示解码阶段隐藏状态。第二种方案思路比较简单将隐藏节点状态分为两部分,第一部分用于计算上下文,第二部分用于计算加权系数,计算方法同一,即不采用全部隐藏状态计算系数。
    第一种Attention机制
    第一种Attention机制

实验效果

  1. 实验训练数据来自于Gigaword,包含N年的新闻语料。
    2.数据预处理包括:1)将新闻的第一段作为编码阶段输入;新闻标题作为解码阶段输入。2)训练数据集过滤保证正文输入不大于50个字符,标题输入不大于25个字符3)仅保留常见的4000个词,其他用UNK表示。
    3.模型理解,1)模型最后一层理解,可以看到不同输入的贡献度。即softmax层输入表示为ot=Wcct+Wh∗ht−1+boo_t=W_c c_{t}+W_h* h_{t-1} + b_oot​=Wc​ct​+Wh​∗ht−1​+bo​,其中c_t和h_t-1分别表示上下文输入和历史信息输入,如果想知道上下文贡献度则直接抹掉h相关输入,即ot=Wcct+boo_t=W_c c_{t}+ b_oot​=Wc​ct​+bo​,其他同理

总结

本文将经典Seq2Seq应用于标题自动生成,提出两种Attention机制,取得不错实验效果。本文中对训练语料处理、训练trick以及对模型理解值得借鉴。

Neural Headline Generation with Minimum Risk Training

模型概览

本文解决问题依然是文本自动生成,不同的是采用最小风险训练误差,而不是常见的基于字或者基于词的误差,这样能够对句子级别输出进行优化。

这里写图片描述

  1. 编码阶段采用BIRNN+GRU单元对输入序列进行编码。
  2. 解码阶段采用RNN+Attention机制,Attention采用标准的soft alignment进行计算。
  3. 最大似然估计:最大化训练集合D中标题生成概率,即LMLE=∑x,ylogP(y∣x;θ)L_{MLE}=\sum_{x,y}log P(y|x;\theta)LMLE​=
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

下一步

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值