본문 바로가기
Vision

Introduction - Attention

by Hotbingsoo 2021. 10. 31.
반응형

 

 

Sequence to Sequence Learning with Neural Networks

Deep Neural Networks (DNNs) are powerful models that have achieved excellent performance on difficult learning tasks. Although DNNs work well whenever large labeled training sets are available, they cannot be used to map sequences to sequences. In this pap

arxiv.org

 

Neural Machine Translation by Jointly Learning to Align and Translate

Neural machine translation is a recently proposed approach to machine translation. Unlike the traditional statistical machine translation, the neural machine translation aims at building a single neural network that can be jointly tuned to maximize the tra

arxiv.org

RNN single cell operation

RNN(Recurrent Neural Network)는 sequence-to-sequence 학습에 효과적인 모델입니다. RNN 계열의 단일 셀의 기본 연산은 위와 같습니다. 

LSTM-based Translation Example

Attention은 2015년 위 논문에서 처음 제안된 개념입니다. Attention 이전의 AI를 이용한 번역은 위와 같은 형태로 진행되었습니다. Sequential data 학습에 유리한 RNN 계열기반 encoder-decoder model에 문장을 넣으면 각각의 벡터화된 단어들은 은닉 state h1 ~ ht를 만들어냅니다. 이 구조에서 context vector 라는 정보가 전달되는데 context vector는 fixed sized vector입니다. 즉 input sequence vector가 짧던 길던 고정된 길이의 context vector로 압축해야 했고 따라서 input sequence 길이에 robust 하지 못한 모델이 됩니다.

 

이 문제를 해결하기 위해 제안된 것이 'Attention' 이라는 개념입니다. 디코더로 전달되는 context vector로 인해 정보가 소실되는 것을 막기 위해 마지막 hidden state 뿐만 아니라 1)모든 hidden state를 이용하고, 2)각각의 hidden state에 얼마나 집중해야 하는지를 계산하는 것이 Attention의 주된 골자입니다 

Concept of Attention

Attention 공부를 위해 여러 블로그를 참고했는데 그중 제가 그나마 이해하기 편했던 그림입니다. 'étudiant' 라는 단어를  만들기 위해선 디코더 부분의 hidden state \(s_{3}\)가 필요할 것입니다. 하지만 'Attention' 개념을 적용하면 디코더의 hidden state 뿐만 아니라 Encoder의 전체 입력 sequence를 참고합니다. 위 그림과 같이 \(s_{3})\와 인코더 부분의 각각의 hidden state를 dot-product 혹은 어떤 함수를 이용해 'Attention Score'를 생성합니다. Attention score에 softmax를 취한 후 인코더부 hidden state를 곱해 새로운 context vector를 생성합니다.

 

이번 포스팅에서 Attention을 아주 간단하게 훑어보았고 다음에 이 attention 개념이 vision 분야에서 어떻게 활용되는지 알아보도록 하겠습니다.

반응형

댓글