Attention์ ๋ํด ์ ๋ง ์ ์ ๋ฆฌ๋์ด ์๋ค๊ณ ์๊ฐํ ๊ธ
์ํค๋ ์ค
์จ๋ผ์ธ ์ฑ ์ ์ ์ ๊ณต์ ํ๋ ํ๋ซํผ ์๋น์ค
wikidocs.net
1. attention์ ํ์์ฑ
seq2seq(=encoder decoder) ๋ชจ๋ธ์
encoder์์์ ์ ๋ณด๋ฅผ context vector๋ผ๋ ํ๋์ ๋ฒกํฐ์ ์์ถํด์ ์ ๋ฌํ๊ณ ,
decoder์์๋ context vector ํ๋๋ฅผ ์ด์ฉํด ์ถ๋ ฅ sequence๋ฅผ ๋ง๋ค์ด๋ธ๋ค.
ํ๋์ ๋ฒกํฐ์ encoder์ ๋ชจ๋ ๋ด์ฉ์ ๋ด์์ผ ํ๋๋ฐ, ์ด ๊ณผ์ ์์ ์ ๋ณด ์์ค์ด ๋ฐ์ํ๊ฒ ๋๋ค.
์ด๋ฌํ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ณ ์ ๋ฑ์ฅํ ๋ชจ๋ธ์ด Attention์ด๋ค.

2. attention
decoder์ ๋งค step๋ง๋ค encoder์ ์ด๋ ๋จ์ด์ ์ฃผ๋ชฉํด์ผ ํ๋์ง ์๋ ค์ฃผ์
์ด๊ฒ์ด attention์ ์์ด๋์ด์ด๋ค.
Attention value๋ฅผ ๊ตฌํ๋ ๋ฐฉ๋ฒ
Attention(Q, K, V) = Attention Value
- ์ดํ ์ ํจ์๋ ์ฃผ์ด์ง query์ ๋ํด์ key์์ ์ ์ฌ๋๋ฅผ ๊ตฌํ๊ณ ,
- key์ mapping๋์ด ์๋ value์ ๋ฐ์ํด์ค๋ค.
- ๊ทธ๋ฆฌ๊ณ query์์ ์ ์ฌ๋๊ฐ ๋ฐ์๋์ด ์๋ value๋ฅผ ๋ชจ๋ ๋ํด์ ๋ฆฌํดํ๋ค.
- ์ฌ๊ธฐ์ ๋ฆฌํด๋ ๊ฐ์ attention value๋ผ๊ณ ํ๋ค.
query, key, value๊ฐ ์๋ฏธํ๋ ๋ฐ
- query : t์์ ์์์ decoder์ hidden state
- key : ๋ชจ๋ ์์ ์์์ encoder์ hidden state
- value : ๋ชจ๋ ์์ ์์์ encoder์ hidden state
Attention ๊ณ์ฐ ๊ณผ์

- attention score ๊ตฌํ๊ธฐ
- t์์ ์ decoder์ hidden state์ ๋ชจ๋ ์์ ์ encoder์ hidden state๋ฅผ ๋ด์ ํ์ฌ attention score ๊ตฌํ๋ค.
- t์์ ์ decoder์ hidden state์ ๋ชจ๋ ์์ ์ encoder์ hidden state๋ฅผ ๋ด์ ํ์ฌ attention score ๊ตฌํ๋ค.
- attention distribution ๊ตฌํ๊ธฐ
- attention score์ softmax ์ ์ฉํ์ฌ attention distribution ๊ตฌํ๋ค.
- attention score์ softmax ์ ์ฉํ์ฌ attention distribution ๊ตฌํ๋ค.
- attention value ๊ตฌํ๊ธฐ
- attention distribution๊ณผ encoder์ hidden state๋ฅผ ๊ณฑํ๊ณ , ํฉํ์ฌ attention value๋ฅผ ๊ตฌํ๋ค.
- attention distribution๊ณผ encoder์ hidden state๋ฅผ ๊ณฑํ๊ณ , ํฉํ์ฌ attention value๋ฅผ ๊ตฌํ๋ค.
- t+1 ์์ ์ decoder hidden state ๊ตฌํ๊ธฐ
- t์์ ์ decoder hidden state์ attention value๋ฅผ ์ด์ฉํ์ฌ t+1์์ ์ decoder hidden state ๊ตฌํ๊ธฐ
'๐ > Coursera_DL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ฝ์ธ๋ผ Deep Learning ์ ๋ฆฌ (2) | 2020.12.27 |
---|---|
WEEK8 : Bleu score (0) | 2020.12.27 |
WEEK8 : beam search in language model (0) | 2020.12.27 |
WEEK8 : negative sampling (0) | 2020.12.26 |
WEEK8 : Word Embedding (word2vec) (0) | 2020.12.26 |