# ML(Hung-yi Lee)_Lecture04. Transformer ###### tags: `Machine Learning` * what is transformer? **Sequence to Sequence的model** 由機器決定output的長度 * ex:speech recongnition、machine translation、speech translation(直接聽到就翻譯,因為世界上有超過半數的語言沒有文字)  * multi-label classification vs multi-class classification * multi-label classification: 同一個object可以屬於多個class 可用seq2seq解(input:一篇文章,output:屬於多少不同class) * multi-class classification 從多個class中選擇某一個class給這個object ## seq2seq ### encoder 給一排vector輸出一排vector(Transformer裡使用self-attention)  1. **residual**直接把input和output相加 2. 結果做layer normalization * 對**同一個feature同一個example不同dimension**的input計算$\sigma$ * output : $x_i'=\frac{x_i-m}{\sigma}$  ### decoder (**Autoregressive**) 輸出結果  * start=begin(special token) * 分數最高的當作output  * 把前一次的output當作下一次的input  #### masked self-attention * 產生$b^1$只會考慮$a^1$,產生$b^2$只會考慮$a^1$、$a^2$(不再關注右邊資訊) * why? 因為在decoder裡output是一個一個產生(先有$a^1$才會有$a^2$),無法考慮後面尚未產生的資訊 #### adding stop token **non-auto regressive model(NAT)**  * 一次產生整串句子 * how to decide output length? * 吃encoder的input去預測decoder長度 * 給一個最大start長度 * advantages: * parallel平行化處裡(AT需要一個一個處理) * controllable output length * NAT performance is worse than AT ([**multi-modality**](https://www.youtube.com/watch?v=VdOyqNQ9aww)) #### encoder如何傳遞資訊  * **cross attention**  ### Training * 每一次decoder在產生一個output都是一個分類問題(minimize cross entropy) * decoder input在訓練時會給正確答案(**teacher forcing**) * **copy mechanism** * 不需要產生庫洛洛,直接從input複製過來  * ex.document$\rightarrow$summary * **beam search** 每次都走眼前最好的路greedy decoding,但最後結果不見得最好,但是要蒐集所有可能路徑是不可能的,因此產生beam search * 建立一個候選名單 * 有時結果好有時結果較差,可能讓speech一直講一樣的話 * if 模型沒有模糊地帶就適合使用beam search,但有時需要machine發揮創意就比較需要再decoder**加入隨機性**  * **exposure bias** 在training時decoder看到的是正確資訊但是在testing時decoder得到的input不一定正確  * 解決 : **scheduled sampling** 給decoder一些錯誤資料去訓練
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up