์์:
(1) LSTM
(2) seq2seq, +attention
(3) Show, Attend and Tell
Reference: Visualization of seq2seqmodel
seq2seq
[1] Sutskever, Ilya, Oriol Vinyals, and Quoc V. Le. "Sequence to sequence learning with neural networks." arXiv preprint arXiv:1409.3215 (2014).
[2] Cho, Kyunghyun, et al. "Learning phrase representations using RNN encoder-decoder for statistical machine translation." arXiv preprint arXiv:1406.1078 (2014).
๋ง ๊ทธ๋๋ก sequence๋ก ์ ๋ ฅ์ ๋ฐ์ sequence๋ก ์ถ๋ ฅํ๋ค.
input ๊ธธ์ด์ output ๊ธธ์ด์ ์ ํ์ด ์์ด ์ ์ฉํ๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก Encoder-Decoder ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๋ค.
Encoder์ด input์ผ๋ก context vector์ ์ถ์ถํ๊ณ ,
Decoder์ context๋ฅผ ๋ฐ์ output์ ์์ฑํ๋ค.
Encoder๊ณผ Decoder์ ๊ฐ๊ฐ RNN์ผ๋ก ๊ตฌ์ฑ๋๋ค.
Encoder์ ๊ฐ cell๋ค์ input๊ณผ ์ด์ cell์ hidden state๋ฅผ ๋ฐ์ ๋ค์ hidden state๋ฅผ ์ถ๋ ฅํ๊ณ ,
Decoder์ ๊ฐ cell๋ค์ ์ด์ cell์ hidden state์ output์ ๋ฐ์ output๊ณผ ๋ค์ hidden state๋ฅผ ์ถ๋ ฅํ๋ค.
Decoder์ ์ฒซ cell์ context vector๊ณผ <sos> ํ ํฐ์ ์ ๋ ฅ์ผ๋ก ๋ฐ๋๋ค.
seq2seq + attention
[3] Bahdanau, Dzmitry, Kyunghyun Cho, and Yoshua Bengio. "Neural machine translation by jointly learning to align and translate." arXiv preprint arXiv:1409.0473 (2014).
[4] Luong, Minh-Thang, Hieu Pham, and Christopher D. Manning. "Effective approaches to attention-based neural machine translation." arXiv preprint arXiv:1508.04025 (2015).
- seq2seq์ context vector์ด bottleneck์ผ๋ก ์์ฉํ๋ค. ์ด์ long sentence์ ์ ๋๋ก ๋์ํ์ง ๋ชปํ๋ค๋ ๋จ์ ์ด ์๋ค.
- seq2seq์ attention ๊ฐ๋ ์ ์ ์ฉํ์ฌ ์ด๋ฌํ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค.
- Attention์ ๋ค์๊ณผ ๊ฐ์ด ํํ๋๋ค.
Attention(Q, K, V) : ์ฃผ์ด์ง Query Q์ ๋ํด ๋ชจ๋ Key K์์ Score value V๋ฅผ ๊ตฌํ๊ณ , ์ด๋ฅผ ๋ชจ๋ ๋ํด์ returnํ๋ค.
- ๋ง์ง๋ง hidden vector(=context vector)์ decoder์ ์ ๋ฌํ๋ seq2seq์ ๋ฌ๋ฆฌ, ๋ชจ๋ cell์ hidden state๋ฅผ decoder์ ์ ๋ฌํ๋ค.
Decoder์ ๊ฐ cell๋ค์ forward ๊ณผ์ ์ดํ Encoder์ hidden state๋ค์ ์ด์ฉํด ๋ค์์ ์ถ๊ฐ์ ์ธ ์์ ์ ๊ฑฐ์น๋ค.
1. Encoder์์ ๋ชจ๋ hidden state๋ฅผ ๋ฐ๋๋ค.
2. ๊ฐ Encoder hidden state์ ํ์ฌ ์์ ์ Decoder hidden state์ ๋ํ score์ ๋ถ์ฌํ๊ณ , softmax๋ฅผ ์ทจํ๋ค. => Attention
- Score์ ํ์ฌ ์์ ์ Decoder hidden state์ ๋ํ ๊ฐ Encoder hidden state์ ์ค์๋๋ฅผ ์๋ฏธํ๋ค.
- ์ฆ, ๊ฐ Encoder hidden state์ score์ ํด๋น input์ ๋ํ weight๋ก ์์ฉํ๋ ๊ฒ.
- ๋งค๋ฒ Decoder output์ ๊ณ์ฐํ ๋๋ง๋ค Encoder์ ๋ชจ๋ ์์ ์ hidden state๋ฅผ ๊ณ ๋ คํ๋ ๊ฒ์ด๋ค.
- Softmax๋ฅผ ์ทจํ score ๊ฐ๋ค์ Attention distribution์ด๋ผ๊ณ ํ๋ค.
* Scoring์ ํ๋ ๋ฐฉ๋ฒ์ ์ฌ๋ฌ ๊ฐ์ง๊ฐ ์์ ์ ์๋๋ฐ, ๊ฐ๋จํ ๋ฐฉ๋ฒ์ decoder hidden state์ encoder hidden state๋ฅผ dot product ํ๋ ๊ฒ.
incredible.ai/nlp/2020/02/20/Sequence-To-Sequence-with-Attention/ ์์ ๋ณด๋ค ์์ธํ ์ค๋ช ๊ณผ ์์๋ฅผ ํ์ธํ ์ ์๋ค.
* ํน์, decoder hidden state์ encoder hidden state๋ฅผ neural network์ ๋ฃ์ด score์ ๊ณ์ฐํ ์๋ ์๋ค. [4]
* lilianweng.github.io/lil-log/2018/06/24/attention-attention.html#whats-wrong-with-seq2seq-model์์ ๋ค์ํ attention์ ์ข ๋ฅ๋ฅผ ํ๋ก ์ ๋ฆฌํด ๋์๋ค.
3. ์์์ ์ป์ (softmax) score๊ณผ Encoder hidden state๋ฅผ ๊ณฑํ ํ ๋ชจ๋ ๊ฐ์ ๋ํด ํ๋์ vector์ ๋ง๋ ๋ค.
์ด๋ ์ค์ํ hidden state๋ ๊ฐ์กฐํ๊ณ , ์ค์ํ์ง ์์ hidden state๋ ์ค์ด๋ ๊ฒ์ด๋ค. ์ด๊ฒ์ด attention์ ๊ฐ๋ ์ด๋ค.
์ด๊ฒ์ด ๊ฐ decoder cell์ context vector์ด ๋๋๊ฒ.
์ฌ๊ธฐ๊น์ง์ ๊ณผ์ ์ ์์์ผ๋ก ์ ๋ฆฌํ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
4. context vector๊ณผ Decoder hidden state๋ฅผ concat ํ Dense layer์ ํต๊ณผ์์ผ output์ ์ถ๋ ฅํ๋ค.
๋ค์ ๋งํด, ๊ฐ cell์์๋
1) ์ด์ hidden state์ ์ด์ output์ ์ด์ฉํด ์๋ก์ด hidden state๋ฅผ ๊ณ์ฐํ๊ณ ,
2) Encoder hidden state set์ ์ด์ฉํด context vector์ ๊ณ์ฐํ๊ณ ,
3) ์๋ก์ด hidden state์ context vector์ ์ด์ฉํด output๋ฅผ ๊ตฌํ๋ ๊ณผ์ ์ ๊ฐ๊ฐ ๊ฑฐ์น๋ ๊ฒ์ด๋ค.
[์ฐธ๊ณ ์๋ฃ]
๊ตฌํ์ ๋์์ด ๋ ๋งํ ๊ธ๋ค.
'๐ Deep Learning > Overview' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[StyleGAN ์๋ฆฌ์ฆ] ProGAN/PGGAN, StyleGAN, StyleGAN2 (0) | 2022.08.19 |
---|---|
[GAN Overview] GAN ์ฃผ์ ๋ชจ๋ธ ์ ๋ฆฌ (GAN survey ๋ ผ๋ฌธ ๋ฆฌ๋ทฐ) (0) | 2022.01.23 |
[Overview] Attention ์ ๋ฆฌ - (1) LSTM (0) | 2021.01.26 |
[Overview] YOLO ๊ณ์ด Object Detection ์ ๋ฆฌ - (1) YOLO (0) | 2021.01.19 |
[Overview] R-CNN ๊ณ์ด Object Detection ์ ๋ฆฌ (Two-stage detector) (0) | 2021.01.08 |