BiLSTM-Attention
《Attention-Based Bidirectional Long Short-Term Memory Networks for Relation Classification》论文笔记
Overview
这篇文章提出了一种特征提取和文本表示的模型。作者提到在文本分类领域,常用的监督学习需要大量的人工标注样本,并且常常需要构建如POS-tagging、NER、dependency parsing等更高级的特征,耗时耗力。为了解决这样的问题,作者提出了这种Attention based的BiLSTM网络,并取得了很好的效果。模型的结构其实很简单,这篇文章也有年头了,但作为之前的经典文章,还是觉得值得复现一下。
Model Structure
模型主要分为五大部分:
- Input Layer:输入层
- Embedding Layer:词嵌入层,本文使用了词向量
- LSTM Layer :BiLSTM层
- Attention Layer :Attention层
- Output Layer:输出层
LSTM Layer
LSTM层中使用的是双向LSTM,这没什么特别的。值得注意的是,本文的LSTM采用了peephole connection,简单来说就是每个时刻的输入增加了上一时刻的cell state,计算公式稍有变化:
i t = σ ( W x i x t + U h i h t − 1 + V c i c t − 1 + b i ) f t = σ ( W x f x t + U h f h t − 1 + V c f c t − 1 + b f ) g t = t a n h ( W x x t + W h h t − 1 + W c c t − 1 + b ) c t = i t g t + f t c t − 1 o t = σ ( W x o x t + U h o h t − 1 + V c o c t − 1 + b o ) h t = o t t a n h ( c t ) i_t\ =\ \sigma(W_{xi}x_t+U_{hi}h_{t-1}+V_{ci}c_{t-1}+b_i) \\ f_t\ =\ \sigma(W_{xf}x_t+U_{hf}h_{t-1}+V_{cf}c_{t-1}+b_f) \\ g_t\ =\ tanh(W_{x}x_t+W_{h}h_{t-1}+W_{c}c_{t-1}+b) \\ c_t\ =\ i_tg_t\ +f_tc_{t-1} \\ o_t\ =\ \sigma(W_{xo}x_t+U_{ho}h_{t-1}+V_{co}c_{t-1}+b_o) \\ h_t\ =\ o_ttanh(c_t) it = σ(Wxixt+