Loading...
2022. 5. 18. 02:09

transformer decoder에 사용된 masked self attention에 대해 알아보고 구현하기

decoder는 특이하게 masked multi head attention을 먼저 수행한다. 이것은 decoder 내부에서 이루어지는 self attention 과정으로 decoder의 input sequence끼리만 이루어진다. 언어모형을 학습시킬때 이미 정답을 아는 상태에서 학습을 시킨다. i go home을 번역하라고 할때 decoder에는 ' 나는 집에 간다'를 넣고 '나는 집에 간다 '를 순차적으로 뱉게 학습을 시킨다는 것이다. decoder에 input으로 ''를 넣어주면 output이 '나는'이 나오길 바라고 '나는'을 input으로 넣어주면 '집에'가 나오길 바란다. 그런식으로 학습을 시킨다. 하지만 이런 학습이 inference에는 어울리지 않는다는 점이다. test과정에서는 정답을 모른..

2022. 5. 16. 20:24

transformer의 decoder 구조 알아보기

decoder의 기본 구조는 이렇다. The decoder is also composed of a stack of N = 6 identical layers. In addition to the two sub-layers in each encoder layer, the decoder inserts a third sub-layer, which performs multi-head attention over the output of the encoder stack. Similar to the encoder, we employ residual connections around each of the sub-layers, followed by layer normalization. We also modify the se..

2022. 5. 16. 01:52

transformer에 사용된 warm up learning rate scheduler

1. warm up learning rate scheduler 최적화 알고리즘인 optimizer의 learning rate는 중요한 hyperparameter인데 보통 하나의 값을 선택하고 전 과정동안 그 값으로 학습을 진행함. 그러나 조금 더 빠르게하면서 모델 성능은 높이고 싶다면 학습 중 변경하는 방법도 생각해볼 수 있음 이런 기법을 learning rate scheduling라고 부른다. 학습 중 적절한 방식으로 learning rate를 변경하면서 학습한다. 모델의 성능을 높이고 학습도 빠르게 할 수 있는 여러 기법들이 있다. warm up learning rate scheduler은 transformer에서 사용한다면 학습이 경험적으로 잘 된다고 많은 경우 알려져있다. 2. 직관적으로 warm..

2022. 5. 13. 01:28

transformer에 사용된 positional encoding에 대하여

1. block based model encoding의 마지막 단계로 residual connection, layer normalization 결과를 feed forward network라는 신경망에 넣어 다시 한번 변환을 거친다. 근데 특별히 왜 했다는 이유는 없는듯?? feed forward network후에도 residual connection을 수행하고 layer normalization을 수행하여 최종적인 encoder의 output인 hidden vector를 얻는다. 2. positional encoding 지금까지 연산의 결과는 사실 sequence의 순서 정보를 전혀 고려하지않았다. 직관적으로 당연하다. x1,x2,x3의 q,k,v를 한번에 만들어서 이것으로 attention을 수행하면서..

2022. 5. 5. 19:03

transformer에 사용된 residual connection과 layer normalization

1. residual connection self attention 구조하에 당시 좋은 성능 향상 기법인 residual add connection, layer normalization을 채택했다. input $X_{t}$의 encoding 결과로 $h_{t}$라는 hidden vector를 얻고 싶은데 multi head attention이 학습하는 결과는$h_{t}-X_{t}$라고 하는 것이며 이 결과에 input $X_{t}$를 그대로 더하여 $h_{t}$라는 목표하는 hidden vector를 얻는다. input의 (1,4)의 multi head attention 결과로 얻은 (2,3)에 단순히 더하여 (3,7)이라는 벡터를 얻는 과정이 residual connection이다. 입력 input과 ..

2022. 5. 3. 18:55

transformer의 메모리 사용량 알아보기

1. layer의 계산적인 측면 self attention의 layer의 계산적인 측면에서 본다면 input sequence의 길이가 n이고 hidden vector의 차원이 d일때 Q는 n*d차원이고 $K^{T}$ 는 d*n차원이므로 $O(n^{2}d)$ RNN은 d차원의 $h_{t-1}$이 $h_{t}$로 변환되기위해서는 $W_{hh}$라는 d*d행렬을 곱하여 계산되는데 input sequence의 길이 n에 대하여 $O(nd^{2})$ input sequence의 길이 n과 hidden vector의 차원 d는 의미적으로 큰 차이가 있는데 hidden vector의 차원은 hyperparameter로 선택할수있는 값이다. 그러나 input sequence는 선택할수 없는 값으로 데이터의 길이에 따라..