MACHINE COMPREHENSION USING MATCH-LSTM AND ANSWER POINTER
摘要
本文介紹一種結合 math-LSTM 和Pointer Net利用end-end的來解決QA問題的方式
模型
最主要的還是 match-LSTM:有兩個句子,一個是前提,另外一個是假設,match-LSTM序列化的經過假設的每一個詞,然後預測前提是否繼承自假設。
簡單的說:帶着問題去閱讀原文,然後用得到的信息去回答問題
- 先利用LSTM閱讀一遍passage,得到輸出的encoding 序列
- 然後帶着question的信息,重新將passage的每個詞輸入LSTM,再次得到passage的encoding信息。但是這次的輸入不僅僅只有passage的信息,還包含這個詞和question的關聯信息,它和qustion的關聯信息的計算方式就是我們在seq2seq模型裏面最常用的attention機制。
- 然後將信息輸入answer模塊,生成答案
下面介紹詳細的模型
1. 預處理層LSTM Preprocessing層
首先對文本和問題分別單獨用LSTM進行單向的encoder
l 是LSTMcell的隱藏層大小,p和q分別是文本passage 和 問題question的長度
代碼很簡單,兩個序列分別經過LSTM序列模型,就得到encoder向量。
lstm_cell_question = tf.nn.rnn_cell_impl.BasicLSTMCell(l, state_is_tuple=True)
encoded_question, q_rep = tf.nn.dynamic_rnn(lstm_cell_question, question,masks_question,dtype=tf.float32)
lstm_cell_passage = tf.nn.rnn_cell_impl.BasicLSTMCell(l, state_is_tuple=True)
encoded_passage, p_rep = tf.nn.dynamic_rnn(lstm_cell_passage, passage,masks_passage, dtype=tf.float32)
2. Match-LSTM 層
帶着qustion來閱讀passage,利用的是利用了 Bahdanau Attention機制機制,具體可以見該論文。
但是爲了詳細描述,在這裏還是詳細的描述一遍:
整體的思路可以看作我們在decoder passage,我們聚焦的是qustion向量:
由attention機制我們可以知道,這裏的
第i個詞的向量爲
令:
其中
# tensorflow 裏面有現成的BahdanauAttention類
match_lstm = BahdanauAttention(l, q)
這樣我們就得到了
這樣我們可以完整的迭代這個序列模型:
同理我們將passage倒敘,可以得到倒敘的LSTM模型
我們令forward和backward得到的轉檯矩陣分別爲
# LSTM Cell
cell = BasicLSTMCell(l, state_is_tuple=True)
lstm_attender = AttentionWrapper(cell, match_lstm)
reverse_encoded_passage = _reverse(encoded_passage)
# bi-dir LSTM
output_attender_fw, _ = tf.nn.dynamic_rnn(lstm_attender, encoded_passage, dtype=tf.float32, scope="rnn")
output_attender_bw, _ = tf.nn.dynamic_rnn(lstm_attender, reverse_encoded_passage, dtype=tf.float32, scope="rnn")
output_attender_bw = _reverse(output_attender_bw)
# concat
output_attender = tf.concat([output_attender_fw, output_attender_bw], axis=-1)
3. Answer Pointer
Answer Pointer的思想是從Pointer Net得到的,
它將
1. sequence,自動生成答案序列, 序列裏面的詞是從passage裏面選取出來的
2. boundary,答案從passage裏面截取,模型生成的是開始和結束下標
Sequence
假設我們的答案序列爲:
其中
簡單的方式是像機器翻譯一樣,直接利用LSTM做decoder處理:
假設
找到passage裏面概率最大的詞的就可以了
這裏也利用上節講的Bahdanau Attention機制,
在預測第k個答案的詞時,我們先計算出一個權重向量
先得到隱藏向量:
計算權重:
然後
代碼和match-LSTM基本一致
Boundary
這種模型很簡單,答案
計算方式和上面sequene模型一樣,只是有亮點不同
- 沒有顯示的結束標記,所有在LSTM input的時候不要補0
as≤ae
實驗
使用預訓練過的詞向量
Boundary模式的answer層憂鬱是固定的,可以用bi-dir LSTM
Boundary模式要注意避免截取的段落過長
後續改進
Question Answering Using Match-LSTM and Answer Pointer
1. 預處理層LSTM Preprocessing層
單向LSTM -> BiLSTM
2. regularization
在所有LSTM外面都加上Dropout,droupout概率爲0.2
3. 調整op,size大小
不同的optimal Adam -> AdaMax
不同的batch-szie
gradient clipping =0.5
實驗效果

圖中可以看出,雖然改進的Final Match-LSTM 在訓練集上面指標下降,但是在測試集上面是有提升的
其實在訓練過程中dropout和batch_normal真的是很好的兩種方式
這個工作並沒有對Match-Lstm層做任何改動
1. 預處理層LSTM Preprocessing層增加attention
P,Q互爲attention聚焦
這個改進其實更近一步,在預處理階段就帶着對方的信息處理每一個詞
2. Conditional Span Decoder
在上文的處理中,answer start 和 end是獨立處理的,這裏還是恢復以來關係:
其實如果做到以來,直接用LSTM其實就是上述的概率
這裏作者做了些改進:
然後

graph 對比圖