Recurrent Neural Network Agenda Recurrent Neural Network - - PowerPoint PPT Presentation
Recurrent Neural Network Agenda Recurrent Neural Network - - PowerPoint PPT Presentation
Recurrent Neural Network Agenda Recurrent Neural Network NER sequence tagging RNN
Agenda
- Recurrent Neural Network ทําไมถึงเหมาะกับการทํา NER หรือ
sequence tagging
- RNN มีิวิธีการทํางานอย่างไร มี parameter อะไรบ้าง
x = feature vector h = hidden activation Peter Griffin lives in Quahog B-PER I-PER O O B-LOC y = label output
Peter B-PER h1 = [x1; h0] Wh + tanh ( ) bh y1 = softmax(Wy h1 + by)
Peter B-PER h2 = [x2; h1] Wh + tanh ( ) bh Griffin I-PER y2 = softmax(Wy h2 + by)
Peter B-PER h3 = [x3; h2] Wh + tanh ( ) bh y3 = softmax(Wy h3 + by) Griffin I-PER O lives
Peter Griffin lives in Quahog B-PER I-PER O O B-LOC
Recurrent Neural Network Parameters
[xt; ht-1] Wh + = tanh ( ) bh ht = tanh(Wh ⋅ [xt; ht−1]) + bh yt = softmax(Wy ⋅ ht + by) ht + ) by ht Wy softmax (
x = feature vector h = hidden activation Peter Griffin lives in Quahog B-PER I-PER O O B-LOC y = label output
Peter Griffin lives in Quahog label = Neutral
RNN as a Classifier
Recurrent Neural Network
- เหมาะกับ Sequence Labeling ที่ต้องใช้บริบทกว้าง เช่น Language
Modeling, NER, ตัดคํา
- เหมาะกับการใช้เป็น classifier เพราะเก็บบริบทได้ครบ
- ในทางปฏิบัติแล้ว train ลําบาก
Training RNN
Concept ที่สําคัญ
- Backpropagation Through Time (BPTT) algorithm
- Exploding gradient
- Vanishing gradient
Backpropagation Through Time
Exploding Gradient
Vanishing Gradient
การเทรน RNN
- RNN Parameter น้อย แต่ว่าเทรนลําบาก
- Exploding gradient ทําให้ Loss เป็น NaN หรือ parameter แกว่ง
มากในแต่ละ iteration --> Gradient Clipping
- Vanishing gradient ทําให้ network ไม่เขยื้อน —> GRU, LSTM
Gated Recurrent Unit (GRU) + Long Short-Term Memory (LSTM)
RNN Cell
Peter ct = tanh(Wc ⋅ [ct−1; xt] + bc)
RNN Cell
ct = tanh(Wc ⋅ [ct−1; xt] + bc) Peter RNN Cell
(Simplified) Gated Recurrent Unit
˜ ct = tanh(Wc ⋅ [ct−1; xt] + bc)
Γu = σ(Wu ⋅ [ct−1; xt] + bu)
ct = Γu * ˜ ct + (1 − Γu) * ct−1
Peter B-PER
(Simplified) Gated Recurrent Unit
˜ ct = tanh(Wc ⋅ [ct−1; xt] + bc)
Peter
(Simplified) Gated Recurrent Unit
˜ ct = tanh(Wc ⋅ [ct−1; xt] + bc)
Γu = σ(Wu ⋅ [ct−1; xt] + bu)
Peter
(Simplified) Gated Recurrent Unit
˜ ct = tanh(Wc ⋅ [ct−1; xt] + bc)
Γu = σ(Wu ⋅ [ct−1; xt] + bu)
ct = Γu * ˜ ct + (1 − Γu) * ct−1
Peter B-PER
(Simplified) Gated Recurrent Unit
˜ ct = tanh(Wc ⋅ [ct−1; xt] + bc)
Γu = σ(Wu ⋅ [ct−1; xt] + bu)
ct = Γu * ˜ ct + (1 − Γu) * ct−1
Peter B-PER
Gated Recurrent Unit
Peter B-PER ct GRU Cell ct−1
Peter B-PER c1 GRU Cell c0 lives GRU Cell O c2 in GRU Cell O c3
Long Short-Term Memory Unit
Peter B-PER ht LSTM Cell ht−1 ct−1 ct
Peter B-PER c1 LSTM Cell c0 lives LSTM Cell O c2 in LSTM Cell O c3
Peter Griffin lives in Quahog B-PER I-PER O O B-LOC
Peter Griffin lives in Quahog B-PER I-PER O O B-LOC RNN
Gated Recurrent Unit
- RNN โดยทั่วไป เรียกว่า Vanilla RNN
- GRU และ LSTM เป็น RNN แบบที่เทรนง่ายขึ้นเพราะ แก้ปัญหา
Vanishing gradient ได้ดี แต่ parameter เยอะขึ้น
Bidirectional RNN
Bidirectional RNN
- Bidirectional Gated Recurrent Unit (Bi-GRU)
- Bidirectional Long Short-Term Memory (Bi-LSTM)
- BiLSTM + CRF
x = feature vector h = hidden activation Peter Griffin lives in Quahog B-PER I-PER O O B-LOC y = label output
Peter lives in Rhode Island B-PER O O B-LOC I-LOC
Peter lives in Rhode Island ht
Peter lives in Rhode Island ht ht
Peter lives in Rhode Island ht ht B-PER O O B-LOC I-LOC [ht; ht]
BI-LSTM / BI-GRU
Peter lives in Rhode Island ht ht B-PER O O B-LOC I-LOC [ht; ht]
BI-LSTM-CRF
Bi-LSTM-CRF in Practice
Word Embedding vs Discrete Features
Huang, Zhiheng, Wei Xu, and Kai Yu. "Bidirectional LSTM-CRF models for sequence tagging." arXiv preprint arXiv:1508.01991 (2015).
- Discrete features เหมาะกับ CRF
- Word embedding เหมาะกับ LSTM
ควรใช้ Pre-trained Embedding
Huang, Zhiheng, Wei Xu, and Kai Yu. "Bidirectional LSTM-CRF models for sequence tagging." arXiv preprint arXiv:1508.01991 (2015).
Almost State-of-the-art POS tagging
Huang, Zhiheng, Wei Xu, and Kai Yu. "Bidirectional LSTM-CRF models for sequence tagging." arXiv preprint arXiv:1508.01991 (2015).
Almost State-of-the-art NER
Huang, Zhiheng, Wei Xu, and Kai Yu. "Bidirectional LSTM-CRF models for sequence tagging." arXiv preprint arXiv:1508.01991 (2015).
สรุปคือยังไง
- Bi-LSTM-CRF เป็นโมเดลที่มีประสิทธิภาพ เทรนไม่ยากมาก และใช้กัน
แพร่หลายตอนนี้ (ปี 2020)
- ควรจะใช้ pre-trained embedding + discrete features
- ไม่แน่เสมอไปว่าจะดีกว่า CRF หรือแม้แต่ Maximum Entropy