The dominant sequence transduction models are based on complex recurrent or
convolutional neural networks that include an encoder and a decoder. The best
performing models also connect the encoder and decoder through an attention
mechanism. We propose a new simple network architecture, the Transformer,
based solely on attention mechanisms, dispensing with recurrence and convolutions
entirely. Experiments on two machine translation tasks show these models to
be superior in quality while being more parallelizable and requiring significantly
less time to train. Our model achieves 28.4 BLEU on the WMT 2014 Englishto-
German translation task, improving over the existing best results, including
ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task,
our model establishes a new single-model state-of-the-art BLEU score of 41.8 after
training for 3.5 days on eight GPUs, a small fraction of the training costs of the
best models from the literature. We show that the Transformer generalizes well to
other tasks by applying it successfully to English constituency parsing both with
large and limited training data.
Transformer 구조의 시초가 되는 논문을 읽고 기본원리를 파악하기 위해서이다. 구현된 코드와 함께 읽어보며 논문에 코드로 구현되는 방법을 함께 공부하고 싶었다.
기존 언어모델 (RNN, LSTM, GRU 등..)들은 time sequence에 따라 output을 생성하기에 훈련 sample들을 병렬화하기 힘들어 computing problem이 있었고 긴 sequence를 처리하기 힘들었다. 이 논문에선 오직 attention mechanism만 활용하여 문장 전체를 한꺼번에 입력받아 병렬처리가 가능하게 했다. GPU활용도가 뛰어나며 성능역시 기존 모델들을 뛰어넘었다.
기존엔 sequence 연산이 순차적으로 이루어져야 하기에 병렬처리가 불가해 computing resource가 너무 많이 들었지만 attention과 position encoding을 통해 해결하고 성능과 연산능력 모두 올려 거대언어모델 학습의 기조를 마련하였다.
이미 attention machnism을 사용하거나 encoder-decoder 구조를 활용하는 방법은 제안되었고 사용되어 왔으나 기본은 RNN, LSTM, GRU와 같은 구조를 사용하고 부가적으로 ansemble하는 방법들이였다. attention만을 사용한 구조는 이 논문이 처음 제안하였다.
encoder-decoder 구조의 seq2seq 모델을 attention 만을 이용하여 구현해서 LLM 학습으로의 확장가능성을 열어주었다. 또한 결과론적인 이야기이지만 encoder와 decoder 구조를 각각 따로 활용한 BERT와 GPT, 둘의 장점을 합친 BART와 같은 모델로 발전할 수 있는 방향도 제시해주었다.
Query, Key, Value
어떤 단어를 나타내는 Query와 문장 내 모든 단어드레 대한 vector를 stack해놓은 Key를 곱해서 attention score 를 만든다.
이는 query에 해당하는 단어와 문장 내 다른 단어와의 관계를 나타낸다.
루트 d_k로 scaling해주는 것은 softmax가 0 근처에서 gradient가 높고, magnitude에선 dot product 값이 커져서 매우 낮은 gradient를 가지기에 학습이 되지 않아서라고한다.
softmax를 통해 query 단어가 다른 단어들과 어느 정도의 correlation이 있는지를 확률 분포 형태로 만들고 value matrix와 dot product를 해줌으로써 기존 vector에 query와 key 간의 correlation 정보를 더한 vector를 만든다.
오직 attention만 사용해서 데이터 병렬화와 연산 감소, 성능 개선까지 이루어내며 Transformer라는 언어모델에서의 기념비적인 구조를 제안해낸 논문이다. 구현된 코드가 많으니 직접 코드와 논문을 함께 살펴보며 코드를 구현하는 방법과 구조를 이해하는 과정을 병행하기에 적절한 논문이다.
- BERT
- GPT
- Sequence to Sequence code
- BLEU