# Sequence to Sequence Learning with Neural Networks
###### tags: `paper notes` `deep learning`
[Paper Link](https://arxiv.org/abs/1706.03762)
---
## Intro
* DNN Model最近在Object detection和Speech recognition都獲得很棒的結果, 但DNN之所以強大是因為這些模型都可以利用**平行運算**讓整個訓練過程有效率地進行。
* 若能有一個能map seq2seq的Domain-indepentent方法會很有用, 因為大部分的問題的input和output都不是fixed的而且unknown
* ex:機器翻譯和語音辨識還有QA
* 這篇裡面利用一個LSTM來讀input sequence (當Encoder) 再用另一個LSTM來提取這些Sequence (當Decoder)
* 第二個LSTM基本上是一個RNN的LM
* LSTM一個有用的特性是可以將variable的input sentence map成一個fixed-dimensional的vector representation,而這正能解決最近的困境

* 意外的是LSTM在這裡的表現沒有因為Long Sentence而變差, 是因為這篇有將input sequence的順序顛倒拿來train
* **這是這篇的主要貢獻之一**
### What is Bean search?
* Beam Search?
* 一個可以拿來測試Seq2Seq model Decoder的演算法
* 取代Greedy algo
* Greedy會將當前預測表中機率最大的詞作為下一個詞的預測去輸出
* Beam search是一次考慮多個詞在一起會是下一句的機率,並找出總合機率最大的那群(Beam)
* 實際做法是Beam search一次選擇多個機率大的詞,數量取決於Beam有多大。
* 選出來後將其互相組合排列做比較,再選出擺在一起機率會最大的那些詞作為輸出
* 可以說是升級版的貪心(?
* Reference:
* [Beam search Wiki](https://en.wikipedia.org/wiki/Beam_search)
* [【機器學習】【seq2seq模型與attention機制,Beam Search】](https://www.itread01.com/content/1547935945.html)
* [Beam Search算法及其应用](http://hongbomin.com/2017/06/23/beam-search/)
* [Seq2Seq中的beam search算法](https://zhuanlan.zhihu.com/p/36029811?group_id=972420376412762112)
## The Model
* RNN可以很簡單的做到一樣的事情,但為什麼不用RNN,而用LSTM?
* RNN必須事先知道input和output的對照(但通常兩者長度不一),而且還有輸出的長度沒辦法大於輸入的限制跟無法處理non-monotonic relationship的問題
* 只有用Seq2Seq結構, RNN才能處理輸入輸出長度不一的問題 (利用Encoder-Decoder去 map)
* RNN還有長期依賴(Long-term dependency)的問題
### 前人的LSTM
* LSTM的目標是能輸入$(x_1,...,x_T$之後輸出**條件機率**$p(y_1,...,y_{T'}|x_1,...,x_T)$
* LSTM先利用最後一層的hidden state得到Input Sequence的dimensional representation $v$再算出條件機率$y_1,...,y_{T'}$

* 每個條件機率的分布都用softmax來表示
* EOS = End of Sequence的加入可以讓模型知道學到哪裡就停止
### 他們的LSTM(號稱有三大不同點)
1. **Two different LSTM**: 一個是給input sequence用另一個是給output sequence用, 主要是為了能在不增加太多運算成本的情況下能增加參數
2. **Deep LSTM**: 他們發現Deep LSTM 的表現 > Shallow LSTM, 因此用了4層的LSTM
3. **Reverse LSTM**:將input sequence Reverse非常有用
* EX:將$c,b,c$ map成$\alpha,\beta,\gamma$
* $a,b,c$原本應該被map成$\alpha,\beta,\gamma$
他們覺得這樣會加強input和output之間的溝通(因為事實上應該是$a$和$\alpha$關係比較深, 模型被強迫去學習糾正
## Experiments
* WMT'14 English to French MT task in two way
* 直接翻譯 不參考SMT system
* Rescore n-best list of SMT baseline
### Dataset details
* 12M sen-tences consisting of 348M French words and 304M English words
### Decoding and Rescoring
* 實驗的主要目標是用很多Sentence pair去train出一個大型的深度LSTM
* maximizing the log probability of a correct transloation $T$ given the source sentence $S$
Training object:

* 一開始先用簡單的left-to-right beam search decoder (a small number $B$ of partial hypotheses, which is prefix of some translation)
* 並在每個timestep都用每個字典中的字詞慢慢擴展假設的數量
* 但因為最後假設的數量變太多 所以就discard了這個方法但留下了log possibilty最高的$B$
* 只要遇到EOS, 這個假設就會從Beam中被移除並且被加到complete hypotheses的集合之中, 表示一段假設的完成
* 模型即使在Beam size=1的時候也能表現得不錯 但 size=2是最好的
* 前面也有提到 有用LSTM來rescore the 1000-best lists produced by the baseline system
## Reverseing the Source Sentence
* **個人覺得是本篇重點**
* 使用此方法可以將 LSTM的perplexity從5.8降到4.7, BLEU分數則是從25.9提升到30.6
* 本篇論文沒辦法完整解釋這個現象發生的原因, 但他們相信這是因為dataset上許多短期依賴造成
* 他們覺得是minimal time lag減少的關係
* 讓Target sentence和source sentence更容易"建立溝通"
* 有做實驗看Long sentence vs Reverse sentece哪個比較有助於LSTM, 結果是Reverse更有效果
## Experimental Results

## Model Analysis


## Conclusion
* 展示了Deep LSTM with a limited vocabulary表現得比標準的SMT with unlimited vocabulary 更厲害
* surprised by the extent of the improvement obtained by reversing the words in the source sentences
* surprised by the ability of the LSTM to correctly translate very long sentences.
## Reference
[從零開始的 Sequence to Sequence](http://zake7749.github.io/2017/09/28/Sequence-to-Sequence-tutorial/)