Loading...
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는 선택할수 없는 값으로 데이터의 길이에 따라..

2022. 5. 2. 21:02

multi-head attentiond 개념 알아보고 간단하게 구현해보기

지금까지 이야기한 것은 word embedding vector들의 self attention을 단 1번만 수행했다는 점인데 이것을 확장하여 여러번 수행하고 싶다는 것이다. 왜 여러번 수행해야할까? 단 1번의 self attention은 1가지 측면에서만 word들의 attention 측면을 고려하지만 필요에따라 attention 측면을 여러 방면에서 수행할 필요가 있다. 특히 매우 긴 문장의 경우 ‘I went to the school. I studied hard. I came back home. I took the rest.’를 생각해보자. 이 문장을 해석하기 위해 단어 I에 대해서 고려해야할 대상은 went, studied, came, took 등 동사 측면도 있지만 그것의 대상이되는 school, ..