Transformer
- attention
- last encoder's layer -> all decoder's layer
- input의 len, domain은 output과 다를 수 있다
- input word의 수에 상관 없이 1번만 돌아 감
- encoder, decoder의 구조는 같지만, parameter는 다르다
- input이 같더라도 같은 seq 내의 단어들에 따라 output이 변할 수 있다 (more flexible)
- O(n^2)의 연산이 필요하므로 bottleneck 발생
- 각 word마다 다른 word들 간의 attention을 계산해야 하기 때문
Encoder
- Self-Attention
- 하나의 vector를 변환할 때 다른 벡터를 변환하려 고려하는 것 - 다른 벡터들에 의존적인 forward
- 1 word -> 3 vector (query, key, value)
- query, key, value를 생성하는 parameter는 shared
- query vector's dimension = key vector's dimension
- q, k, v를 통해 input word를 new embedding vector로 변환
- 각 단어마다 score vector를 계산해야 함
- score vector = encoding할 word의 query vector와 나머지 word의 key vector를 dot product
- 다른 word와 얼마나 관계가 있는가
- 어떤 단어를 주의 깊게 봐야 하는가
- score vector -> normalization
- key vector's dimension의 제곱근을 나누어 준다
- 정규화된 score vector를 softmax = attention weight
- encoding vector = weighted sum of (attention weight, value vector)
- encoding vector's dimension = value vector's dimension (single head attention일 때만)
- Multi-head Attention
- 1 word에 대해 query, key, value vector를 1개가 아닌 n개 생성
- 1 word에 대해 n개의 encoded vector를 얻음 (attention heads)
- word vector(input)'s dimension = encoded vector's dimension
- n개의 encoede vector를 행렬곱을 통해 word vector(input)과 같은 차원으로 이동
- Positional encoding
- sequential data의 특징을 살리기 위해 단어의 위치를 저장
- input에 bias를 더함 (주기함수)
- Feed Forward Neural Network
- input layer - hidden layer - output layer
- encoded vector에 대해 independent, 동일한 network
Decoder
- last encoded의 key, value를 decoder의 모든 layer에 전송
- masking : prev word에 대해 dependent, 이후에는 independent
- prev word에 대해 query 생성, key, value는 last encoded vector 활용
- final layer : word distribution - softmax
Vision Transformer
- image를 split하여 각각의 subpatch를 linear layer를 통하여 input
'부스트캠프 AI Tech > Deep Learning' 카테고리의 다른 글
Generative Model (0) | 2022.02.08 |
---|---|
RNN (0) | 2022.02.08 |
CV application (0) | 2022.02.08 |
Modern CNN (0) | 2022.02.08 |
Optimizer (0) | 2022.02.07 |