๐ง๐ปโ๐ป์ฉ์ด ์ ๋ฆฌ
Neural Networks
Recurrent Neural Network
LSTM
Attention
https://arxiv.org/abs/1706.03762
Attention Is All You Need
The dominant sequence transduction models are based on complex recurrent or convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new
arxiv.org
Transformer
์ด์ ๋ Attention๋ง ๊ฐ์ง๊ณ , ์ํ ๊ตฌ์กฐ ์์ด ๋ค๋ฃจ๊ฒ ๋ค๋ ๋ ผ๋ฌธ์ด ๋ฑ์ฅํ์ต๋๋ค.
Attention ์์์ ์๋ก์ ์ฐ๊ฒฐ๊ด๊ณ๋ฅผ ์ฐพ๋ ๋ฐฉ๋ฒ์ ๋์ ํ๋ ๊ตณ์ด ์ํ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ ธ๊ฐ ํ์๊ฐ ์๊ฒ ๋ฉ๋๋ค.
์ฌ๊ธฐ์ self-attention๊ณผ Transformer๊ฐ ๋์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ด๊ฒ์ด ๋ฐ์ ํ์ฌ BERT, GPT๊ฐ ๋ฑ์ฅํฉ๋๋ค.

์ ์์์ ๋จผ์ ๋ด ์๋ค.
์ด๊ฒ์ ์ด์ ์ attention์์ ๋ณธ, ์ ์ฌ๋, weight, context๋ก ํํ๋ฉ๋๋ค.
์ด context ์์ฒด๊ฐ Attention์ด๋ผ๊ณ ๋ณด๊ฒ ์ต๋๋ค.

์ด ์์์์๋ ์ ์ฌ๋๊ฐ ์กด์ฌํฉ๋๋ค.
softmax ๊ดํธ ์์ ์๋ ๊ฐ์ Q์ K์ ์ ์ฌ๋๋ฅผ ๊ณ ๋ คํ ๊ฒ์ ๋๋ค.
์ Attention ๊ตฌ์กฐ๋ง ์ผ์ ๋๋ additive ์ ์ฌ๋๋ฅผ ๊ณ์ฐํ์์ง๋ง, ์ด ์์์ dot product ์ ์ฌ๋๋ฅผ ๊ณ์ฐํฉ๋๋ค.
๋ด์ ์ด์ฃ .
๊ทธ๋ฆฌ๊ณ d k์ root ๊ฐ์ผ๋ก ๋๋ ์, scale์ ๋ฐ๋ผ ๊ฐ์ด ๋๋ฌด ์ปค์ง๋ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ์ฌ ๋ชจ๋ธ์ด stableํ๊ฒ ๋์ต๋๋ค.
์ด d k๋ dimension์ผ๋ก ๋๋์ด unit vectorํ ์ํต๋๋ค.
๊ทธ๋์ ์ด ๋ถ๋ถ์ scaled dot product๋ผ๊ณ ํฉ๋๋ค.
๊ทธ๋์ ์ softmax ๋ถ๋ถ์ ๋น์ฐํ weight๊ฐ ๋ฉ๋๋ค.
์ด weight์ ๋ ๋ค๋ฅธ matrix V๋ฅผ ๊ณ์ฐํด์ ๋๊ฐ๋ ๊ฒ์ด Attention์ ๋๋ค.
๊ฒฐ๊ตญ Weighted V๋ผ๊ณ ๋ณผ ์ ์๊ณ , ์ด weight๋ Q์ K์ ์ ์ฌ๋์ ๊ธฐ๋ฐํ weight์ ๋๋ค.
์ด Q์ธ Query๋ Decoder์์์ target์ด ๋๋ hidden state๋ผ๊ณ ๋ฐ๊ฟ ์๊ฐํ ์ ์์ต๋๋ค.
๊ทธ๋์ Key์ธ K๋ encoder์์ ๋ชจ๋ state๊ฐ key ํ๋ณด๊ฐ ๋ฉ๋๋ค.
์ฌ๊ธฐ์ ์ ์ฌ๋๊ฐ ๋ค ๊ณฑํด์ ธ์ ๋๊ฐ๋, Key์ Value๋ ๊ฐ์ ๊ฐ์ ์๋ฏธํฉ๋๋ค.
์ด๊ฒ์ ์ด์ ์ ์ฒด state์ ๋ํด ์๊ฐํด๋ณด๊ฒ ์ต๋๋ค.
์๋๋ Encoder์ Attention ๊ฐ์ ๊ณ์ฐํ์ฌ Decoder์ ์์ธก์ ๋์์ ์คฌ๋ค๋ฉด,
์ด๋ฒ์๋ Encoder์ Encoder ์ฌ์ด์ Attention์ ๊ตฌํฉ๋๋ค.
Encoder๋ sequence๋ฅผ vectorํ๋ง ํด์ ๋ฃ์ง ๋ง๊ณ ์ ๋ ฅ๋ค ์ฌ์ด์ ์ ์ฌ๋๋ฅผ matrix๋ก ๋ง๋ค์ด์ ์ ๋ ฅ์ผ๋ก ๋ฃ์ผ๋ฉด ์ข์ง ์์๊นํ๋ ์๊ฐ์ ํ๊ฒ ๋ฉ๋๋ค.
i am a student ์์,
์ด ๋จ์ด๋ค์ด ๋ ๋ฆฝ์ ์ธ ์ ๋ ฅ์ด ๋๋ ๊ฒ์ด ์๋๋ผ, ์ํ์ผ๋ก ๋ฌถ๋ ๊ฒ์ด ์๋๋ผ, ์ด๋ค ๋จ์ด์ ์ด๋ค ๋จ์ด๊ฐ ๊ด๋ จ ์๋ค๋ ๊ฒ์ matrixํ ํด์ ํํํ๋ฉด ๋ ์ข๊ฒ ๋ค๋ ๊ฒ์ ๋๋ค.
๋๋ Decoder์ Decoder ์ฌ์ด์ ์ ์ฌ๋๋ฅผ ๋ด ๋๋ค.
๊ทธ๊ฒ์ ํตํด ์์ธก ๊ฐ๋ค ์ฌ์ด์ ์ ์ฌ๋๋ฅผ ์ดํ๋๋ค.
๊ทธ๋ฆฌ๊ณ ์์ฒ๋ผ Encoder์ Decoder ์ฌ์ด์ ์ ์ฌ๋ ์ ๋๋ค.
์ด๋ ๊ฒ 3๊ฐ์ง ๊ฒฝ์ฐ์ ์๊ฐ ์กด์ฌํฉ๋๋ค.
์ด๋ฌํ ๊ฒ๋ค์ ์กฐ๊ธ ๋ ๊ณ ๋ คํ์ฌ, ์ผ๋ฐํํด์ ์๊ฐํด ๋ณธ๋ค๋ฉด,
Query ์์ฒด๋ ๊ฐ๋ฅํ hidden state๊ฐ ๋ ์ ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ Key์ Value ๋ํ ๊ทธ๋ ์ต๋๋ค.

๊ทธ๋ฌ๋, scaled dot product attention์ ํ๋๋ฐ,
Q์ K๊ฐ Matmul๊ณผ scale์ ํ๋ ๊ฒ์ด softmax ๊ดํธ ์์ ์๋ ์์ ํด๋นํฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ , mask๋ optional์ ๋๋ค.
softmax๋ฅผ ๊ทธ ๋ค์์ผ๋ก ํด์ค๋๋ค.
๊ทธ๋ฆฌ๊ณ V๊ฐ ๋ค์ด๊ฐ์ matmul์ ํฉ๋๋ค.
์ด๊ฒ์ ํตํด,
Encoder-Decoder ๋ฟ๋ง ์๋๋ผ, Encoder-Encoder, Decoder-Decoder ๋ผ๋ฆฌ๋ ์๊ฐํด๋ณผ๋ง ํ๋ค๋ ๊ฒ์ ์๊ฒ ๋์์ต๋๋ค.
์ด scaled dot-product๋ฅผ ํ ๋ฒ๋ง ํ๋ ๊ฒ์ด ์๋,
Multi-head attention์ ์ฌ์ฉํ์ฌ parrallelํ๊ฒ ์ฌ๋ฌ ๋ฒ ํด์ค๋๋ค.

์ด๊ฒ์ sequentialํ๊ฒ ์ฌ๋ฌ ๋ฒ์ด ์๋, parrallelํ๊ฒ ์ฌ๋ฌ ๋ฒ์ ๋๋ค.
์ผ๋จ ์ด ๋ ผ๋ฌธ์์๋ ์์ ๊ฐ์ด input word๋ค์ vector๋ก ํํํ๋ ๋ฐ, 512์ฐจ์์ผ๋ก ํํํฉ๋๋ค.
์๋ฅผ ๋ค์ด, ์ด๋ค sequence๊ฐ 512 ์ฐจ์์ด ์๋ค๊ณ ํฉ์๋ค.
๊ทธ๋ ๋ค๋ฉด ์ด ๊ฒ์, 64์ฐจ์์ฉ 8๊ฐ๋ก Attention์ ์งํํ๋ ๊ฒ์ด, ๋ณ๋ ฌ์ ์ผ๋ก Attention์ ์์ผ์ฃผ๋ ๊ฒ์ด ํจ์ฌ ์ ๋ฆฌํ๋ค๊ณ ์๋ ค์ก์ต๋๋ค.
์ด๋ ๊ฒ ํฐ 512 ์ฐจ์์ word embedding์ ๋ํด ํ ๋ฒ์ Attentionํ์ง ๋ง๊ณ , linear mapping์ ํตํด์ ์ฐจ์์ ์ค์ธ ๋ค์์ ๊ทธ๊ฒ์ ๋ณ๋ ฌ์ ์ผ๋ก Attentionํ๋ ๊ฒ์ด ์ ๋ฆฌํ ๊ฒ์ ๋๋ค.
๊ทธ๊ฒ์ด ์ด Multi-head Attention์ ๋๋ค.
๊ทธ๋์ ์ ์์๊ณผ ๊ฐ์ด 512๋ฅผ 8๊ฐ๋ก projectionํฉ๋๋ค.
์ด projection์ ์๋ก์ด trainable parameter๋ฅผ ํตํด์ ํฉ๋๋ค.

์ฌ๊ธฐ์ Q, K, V๋ ์ ๋ถ 512์ฐจ์์ ๋๋ค.
์ด๊ฒ์ ๊ทธ๋๋ก ๋ฃ์ผ๋ฉด ๋๋ฌด ํฌ๋ ์ด๊ฒ์ ์ค์ ๋๋ค.
512 ์ฐจ์์ 64 ์ฐจ์์ผ๋ก ์ค์ ๋๋ค.
์ด๊ฒ์ด Linear Mapping์ ๋๋ค.
512 ์ฐจ์์ 64 ์ฐจ์์ผ๋ก ์ค์์ผ๋, ์ ๋ณด๋๋ 1/8 ์ ๋ ์ค์์ต๋๋ค.
์ด๊ฒ์ ๋ณด์ ํด์ฃผ๊ธฐ ์ํด์ h ๊ฐ 8๋ก,
8๊ฐ์ head๋ฅผ ๋์ด parellelํ๊ฒ 8๋ฒ์ Attention์ ์งํํฉ๋๋ค.
๊ทธ๋์ ์ ์์์์๋ Attention์ด 8๋ฒ ์ ์ฉ๋์ด ๊ฐ๊ฐ์ ๊ฒฐ๊ณผ head_1 ~ head_h๋ฅผ ๊ฐ์ง๋๋ค.
์ด๊ฒ ๊ฐ๊ฐ๋ 64์ฐจ์์ผ๋ก h์ธ 8๊ฐ ๋งํผ ๋์ต๋๋ค.
์ด๊ฒ์ concatenate๋ฅผ ํตํด ์ญ ๋ถ์ฌ์ค๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋ง์ง๋ง์ Linear transformation ํ output์ ๋ฑ์ด๋ ๋๋ค.


์ฌ๊ธฐ ์ด๋ฌํ ๋จ์ด๊ฐ ์๋ค๊ณ ํฉ์๋ค.
๊ฐ ๋จ์ด๋ฅผ 512 ์ฐจ์์ผ๋ก mappingํ๋ฉด ์์ ๊ฐ์ด ๋์ต๋๋ค.
์ด๊ฒ์ 8๊ฐ๋ก ๋๋์ด parellelํ๊ฒ mappingํฉ๋๋ค.
์ด 64 ์ฐจ์์ผ๋ก mapping๋ ๊ฒ์ด Q, K, V ์ค ๋ค ๋ ์ ์์ต๋๋ค.
๊ทธ๋์ ์ด ๊ฐ๋ค ์ค Q_1 ~ Q_h, K_1 ~ K_h, V_1 ~ V_h๊ฐ ๋ค ๋์ต๋๋ค.
๊ทธ๋์ ๊ฐ๊ฐ์ scaled dot product๋ฅผ ํตํด์ attention๊น์ง ๊ฐ๋ฉด,
Attention_1 ~ Attention_h๊น์ง์ ๊ฒฐ๊ณผ๊ฐ ๋์ค๊ฒ ๋ฉ๋๋ค.
์ด Attention์ ๊ฒฐ๊ตญ softmax() x V์ ๋๋ค.
softmax๋ scalar ๊ฐ๋ค์ด vectorํ ๋์ด ๋ค์ด๊ฐ ๊ฒ์ด๊ตฌ์.
๊ทธ๋์ ๊ฒฐ๊ณผ๊ฐ V์ dimension๊ณผ ๋๊ฐ์ด ๋์ต๋๋ค.
๊ทธ๋์ Attention๊ฒฐ๊ณผ๋ฅผ concatenateํฉ๋๋ค.
์์ ๊ฐ์ด Attention_1 ~ Attention_h๊น์ง๋ฅผ ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ์ฐจ๋ก๋ก ์ด์ด ๋ถ์ ๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ต์ข ์ ์ผ๋ก W_o๋ฅผ ํตํด์ linear transformation์ ๊ฑฐ์ณ ๋๊ฐ์ size๋ก ๋ฑ์ด๋ ๋๋ค.
์ด๊ฒ์ด multi-head attention์ ๊ฒฐ๊ณผ์ ๋๋ค.
์ด๊ฒ์ encoder์ผ ์๋ ์๊ณ decoder์ผ ์๋ ์๊ณ ์๋ก ๊ต์ฐจ๋ ์๋ ์์ง๋ง,
word๋ค์ด ์์ผ๋ฉด, ์ด word๋ค์ ๊ฐ๊ฐ์ ๊ด๊ณ์ฑ์ผ๋ก ํํ๋ matrix๊ฐ ์ถ๋ ฅ๋๊ฒ ๋ฉ๋๋ค.

๊ทธ๋์ ์ด transformer ๊ตฌ์กฐ๋ฅผ ๋ด ์๋ค.
๋ชจ๋ ๊ฒ ๋ค parallelized calculation์ ๋๋ค.
RNN์ ์ํ๋๋ฉฐ sequentialํ ๊ตฌ์กฐ๋ฅผ ๋ณด์ ๋๋ค. RNN์ ์ด์ ์์ ์ด ๋ค์ด๊ฐ์ผ ๋ค์ ์์ ์ด ๋ค์ด๊ฐ ์ ์๋ ๊ฒ์ด์ง์.
๊ทธ๋ฐ๋ฐ Transformer์ ๊ตฌ์กฐ๋ ๊ฐ๊ฐ์ ์์ ์ด ๊ทธ๋๋ก ์ฌ๋ผ๊ฐ์ ์์์ Attention ๋๊ณ ,
๊ฐ๊ฐ์ด Attention์ด ๋์ด ๋ชจ๋ ๋ค์ด๊ฐ์ ์ถ๋ ฅ์ด ๊ทธ๋๋ก ๋์ค๋ ๊ตฌ์กฐ์ ๋๋ค.
์ฆ, hidden state๋ค ๋ผ๋ฆฌ ์ํ์ด ๋์ง ์์ต๋๋ค.
์ฌ๊ธฐ์๋ ์ ๋ ฅ์ ์๋ sentence์ ์ถ๋ ฅ์ ์๋ sentence ๋ค์ด ๊ธฐ๋ค๋ฆด ํ์๊ฐ ์์ต๋๋ค.
๊ทธ๋ฅ parallelํ๊ฒ ๋์์ ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํฉ๋๋ค.
๊ทธ๊ฒ Transformer ๊ตฌ์กฐ์ ๊ฐ์ฅ ํฐ ํจ์จ์ฑ์ ๋๋ค.
๊ทธ๋ฆผ์์ ์ข์ธก์ด encoder, ์ฐ์ธก์ด decoder ๋ถ๋ถ์ ๋๋ค.

๊ทธ๋ฆฌ๊ณ ๊ทธ๋ฆผ์ ์ด positional encoding์ด ์์ต๋๋ค.
์ฐ๋ฆฌ๊ฐ ์์๋ผ๋ ๊ฒ ์์ด parallelํ๊ฒ ์ฒ๋ฆฌ๋๋ค ๋ณด๋, ๋จ์ด๊ฐ ์ด๋ ํ ์์์๋์ง๊ฐ ๋ฌด์๋๋ ๋๋์ด ๋ญ๋๋ค.
๊ทธ๋์ positional encoding์ ํตํด์ ์ด ๋จ์ด๊ฐ ์ด๋์ ์์๋์ง highlight๋ฅผ ํด์ค๋๋ค.
๊ทธ๋์ ์์ ๊ฐ์ด ๋จ์ด์ ๋ํด embedding๋ vector์ ๊ทธ ๋จ์ด์ ๋ํ positional encoding ๊ฐ์ ๊ฐ๊ฐ ๊ตฌํด ๋ํ์ฌ ์ด ๋จ์ด๊ฐ ์ด๋์ ์์๋์ง ์กฐ๊ธ ๋ ๊ฐ์กฐํด์ค๋ค๊ณ ๋ณด์๋ฉด ๋๊ฒ ์ต๋๋ค.
์ด๊ฒ์ sin ๊ทธ๋ํ๋ฅผ ํตํด์ ์งํํฉ๋๋ค.
๊ทธ ๋ค์ multi-head attention์ ์งํํฉ๋๋ค.
์ ๊ทธ๋ฆผ์๋ 3๊ฐ์ง ์ด์ง๋ง ์ค์ ๋ก๋ ์์ฒญ๋๊ฒ ๋ง๊ณ , ์ฐ๋ฆฌ๊ฐ ์์๋ก ๋ค์ 512 ์ฐจ์์ ๋ํด 64 ์ฐจ์์ฉ 8๊ฐ๋ก ๋ณธ ๊ฒฝ์ฐ์ ๋ํด์๋ 8๊ฐ๋ก ๋๋๊ฒ ๋๋ ๊ฒ์ ๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋์ ๋ค์ด๊ฐ๋ ADD & Norm ํญ๋ชฉ์ redisual network๋ฅผ ๊ฐ๋ฅดํต๋๋ค.
์ด ๋ํ ์ด attention์ด ๊ธธ์ด์ง๋ค ๋ณด๋ ์์์๋ ์ ๋ณด๋ฅผ ๊น๋จน์ ์ ์์ด,
skip connection ์ ์ฌ์ฉํ์ฌ residual ๋ถ๋ถ์ ์ตํ๋ผ๋ ๊ฒ์ด๊ฒ ์ฃ .
๊ทธ๋์ Add๊ฐ residual network, Norm์ด layer normalization์ ๋๋ค.
layer ๋ผ๋ฆฌ normalization ์์ผ์ฃผ์ด Attention ๋ผ๋ฆฌ ๋๋ฌด ํฐ ์ฐจ์ด๊ฐ ๋์ง ์๋๋ก ํฉ๋๋ค.
๊ทธ ๋ค์ feed forward๋ฅผ ํตํด ํ ๋ฒ ๋ ์ฐ์ฐ๊ณผ์ ์ ๊ฑฐ์นฉ๋๋ค.
์ ๋ ฅ๊ณผ ์ถ๋ ฅ์ dimension์ ๊ฐ๊ฒ ๋ง์ถฐ์ฃผ๋ฉด์ ๋ง์ด์ฃ .
๊ทธ๋ฆฌ๊ณ ๋ skip connection์ด ์กด์ฌํฉ๋๋ค.
์ด ๋ถ๋ถ์ด Encoder ์ ๋๋ค.
Encoder๋ ์ ๋ ฅ์ Parallelํ๊ฒ ๋ฐ์์, ์ ๋ ฅ ์ฌ์ด์ self-attention์ ์งํํฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ Decoder๋ ๋ด ์๋ค.
Decoder๋ ๋๊ฐ์ด output์ด ๋ค์ด๊ฐ์ positional encoding ํด์ค ๋ค์,
Masked multi-head attention ํฉ๋๋ค.
์ด๊ฒ๋ decoder-decoder ์ฌ์ด์ Attentionํ๊ณ ,
์ Encoder์์๋ encoder-encoder ์ฌ์ด์ Attention์ ๋๋ค.
๊ทธ๋ฐ๋ฐ, ์ฐ๋ฆฌ๊ฐ ๋ฒ์ญ์ ํ๋ค๊ณ ํ์ ๋, ๊ทธ ํ์ ๋์ค๋ ์ ๋ณด๋ค์ ๋ฏธ๋ฆฌ ๊ฐ์ถ ์ ์์ต๋๋ค.
๊ทธ๋์ ์๋ ๊ทธ๋ฆผ์ฒ๋ผ Encoder์์๋ ๋จ์ด์ sentence๋ฅผ ์ ๋ถ ๋ค ๋ฐ์๋ค์ธ ๋ค์ ๋ฒ์ญ์ ์์ํ๋, ๊ทธ๋ฆผ์ฒ๋ผ ๋ชจ๋ ๊ตฌ์กฐ๊ฐ ๋ค ์๋ก๋ฅผ attentionํ ์ ์์ต๋๋ค.

๊ทธ๋ฐ๋ฐ, decoder์์๋ ์์ฐจ์ ์ผ๋ก ๋ฒ์ญ์ด ๋์ด์ ๋์ค๋๊น ์๊ธฐ ์ ์ ๋์จ ๊ฒ๋ง ์ฐธ๊ณ ๋ฅผ ํ ์ ์์ต๋๋ค.
๊ทธ๋์ ์ด Masked multi-head attention์ด๋ผ๋ ๊ฒ์ ์๊ธฐ ์ ์์ ์ ๊ฒ๋ง attention์ ๊ณ์ฐํ๊ฒ ๋ค๋ ๊ฒ์ ๋๋ค.
๊ทธ๋ฆฌ๊ณ Decoder์์์๋ง attentionํ๋ ๊ฒฐ๊ตญ Masked multi-head Decoder Self-Attention์ด๋ผ๊ณ ๋ณผ ์ ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๊ทธ ์๋ถ๋ถ์ ๋ณด๊ฒ ์ต๋๋ค.
Encoder์ ์ ๋ณด๋ฅผ ๋ฐ์์ Attention์ ํฉ๋๋ค.
๊ทธ๋์ ์ ๊ทธ๋ฆผ์ ๋ง์ง๋ง ๋ถ๋ถ์ Encoder-Decoder Attention ๊ตฌ์กฐ๋ก, Encoder์ Decoder์ ๊ด๊ณ์ ๋ํด์ Attentionํด์ฃผ๋ ๊ฒ์ ๋๋ค.
์ด ๋ถ๋ถ์ ์ฐ๋ฆฌ๊ฐ ์์์ ๋ค๋ฃฌ ๊ฒ๊ณผ ๊ฐ์ concept์ด๋ผ๊ณ ๋ณผ ์ ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋๊ฐ์ด feed forwardํ๊ณ residual ํ๊ณ , ๊ทธ๋ฆฌ๊ณ linear transformation, softmax์์ output์ ๊ณ์ฐํ๋ ๊ตฌ์กฐ์ ๋๋ค.
์ด๊ฒ transformer ๊ตฌ์กฐ๋ผ๊ณ ๋ณผ ์ ์์ต๋๋ค.
๊ทธ๋์ ์์ ๊ฐ์ ๋ด๋ถ ๊ตฌ์กฐ๋ฅผ encoder, decoder ๋ชจ๋ N๋ฒ์ ์งํํฉ๋๋ค.
๊ทธ๋์ ๋ง์ฝ, ์์ด ๋ฌธ์ฅ์ด ๋ค์ด์๋ค๋ฉด,
์ฌ๊ธฐ์ encoder transformer๊ฐ N๋ฒ์ด ๋ถ์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ํ๊ตญ์ด๊ฐ ๋ค์ด์๋ค๋ฉด decoder transformer๋ N๋ฒ์ด ๋ถ์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ต์ข ์ถ๋ ฅ์ ํ๋ ๊ตฌ์กฐ์ ๋๋ค.
์ด ํ๊ตญ์ด ๋ฌธ์ฅ์ด๋ผ๋ ๊ฒ์ ์ ๋จ๊ณ์์ ์์ธก๋ ํ๋๋ง ๋ค์ด์ฌ ์ ์์ต๋๋ค.
๊ทธ๋์ ์ ๋จ๊ณ ์์ธกํ ๊ฒ์ ํ๋ํ๋ ๊ธฐ๋ค๋ฆด ์ ์์ผ๋ mask๋ฅผ ํด๋๋ ๊ฒ์ ๋๋ค.
์ด masked๋ฅผ ํตํด ์๊ฐ์ ์ธ ๊ฐ๋ ์ ์ด๋์ ๋ ๋ฐ์ํ๋ค๊ณ ๋ณผ ์ ์์ต๋๋ค. Decoder-Decoder self-attention์์ ๋ง์ด์ฃ .
์ด๋ฌํ ๊ฒ๋ค์ parallelํ๊ฒ ์ฒ๋ฆฌํ๋ ๋ฐ์ ์ค๋ ์ฅ์ ์ ๊ณ์ฐ์ ํจ์จ์ฑ์ ๋๋ค.
์๋ BPTT๋ฅผ ํด์ผํ์ง๋ง, ๋ณ๋ ฌ์ ์ด๋ True time ๊ฐ๋ ์ด ์์ด์ง๋๋ค.
๊ทธ๋ฅ Backpropagation๋ง ๊ฐ์ง๊ณ ํด๊ฒฐ์ด ๋ฉ๋๋ค.
๊ทธ๋์ ์๋์ ๊ฐ์ transformer๋ก attention๋ ์์๋ค์ ๋ณผ ์ ์์ต๋๋ค.

์ด๊ฒ์ encoder์ decoder ์ฌ์ด์ attention์ด๋ฉฐ,
์ด๊ฒ์ multi-head์ ๋ํด์ ๊ฐ head๊ฐ parallelํ๊ฒ ์ ๋ณด๋ฅผ ์ฒ๋ฆฌํ์ฌ attentionํ ๊ฒ์ ํํํฉ๋๋ค.
multi-head๋ก ํ ์ด์ ๋ ํ๋ ํ๋์ word embedding์ ๊ทธ ์ฐจ์์ ์ง์ ๋ณด์ง ๋ง๊ณ , projection ์์ผ์ ์ ๋ณด๋ฅผ ์ถ์ํ ๋ค์์ parallelํ๊ฒ multi๋ก ๋ณด๋ ๊ฒ์ด ์คํ๋ ค ์ ๋ฆฌํ๋ ๊ทธ๋ฌํ ๊ฒ์ด ๋ฐ์๋ ํํ์ ๋๋ค.
'Artificial Intelligence > Deep Learning' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Deep Learning] Deep Generative Models(1) - VAE (0) | 2023.05.29 |
---|---|
[Deep Learning] Autoencoders (0) | 2023.05.23 |
[Deep Learning] Recurrent Neural Network (3) - Attention (0) | 2023.05.19 |
[Deep Learning] Recurrent Neural Network (2) - LSTM (0) | 2023.05.17 |
[Deep Learning] Recurrent Neural Network (1) (1) | 2023.05.16 |