Show, Attend and Tell: Neural Image Caption Generation with Visual Attention

Image Caption Generation with Attention Mechanism: Model details

이 논문 역시 다른 기존 deep learning caption generator model들처럼 image에서 caption을 생성하는 과정을 image라는 언어에서 caption이라는 언어로 ‘translatation’ 하는 개념을 사용한다. 따라서 이 논문은 machine translation의 encoder-decoder 개념을 사용하게 되는데, encoder는 우리가 잘 알고 있는 CNN을 사용하고, decoder로 RNN, 정확히는 LSTM을 사용하게 된다. 이 논문의 핵심이라고 할 수 있는 attention 개념은 LSTM에서 사용된다.

이 논문에서 제안하는 모델을 그림으로 표현하면 다음과 같다.

Encoder: CNN

Encoder CNN은 주어진 이미지를 input으로 받아, output으로 feature vector 를 내보낸다. 이 CNN의 마지막 layer는 총 개의 filter로 이루어져있으며, 각각의 filter마다 D 개의 neuron을 가지도록 설계하였다. 즉, 다음과 같이 쓸 수 있다

이 논문에서는 encoder를 위한 CNN으로 VGG network를 선택하였는데, 19 layer짜리를 사용한 것 같고, VGG11 layer로 pre-training만 시키고 fine-tunning은 하지 않은 상태로 사용했다고 한다. 당연한 얘기지만, VGG 네트워크말고도 다른 네트워크도 사용가능하다.

Decoder: LSTM

이 논문은 decoder로 LSTM을 사용한다. 이 LSTM은 매 time stamp  마다 caption vector 의 한 element 를 생성한다. 즉, 전체 ‘unfold’ 하게되는 시간은 caption의 길이 와 같다. 즉 이 LSTM은 한 time stamp  마다 바로 전 hidden state 과 바로 전에 generate된 단어 을 input으로 받아서 지금 time stamp에 해당하는 단어 를 생성하는 것이다. 이 논문에서 사용하는 LSTM 모델은 다음과 같다.

이 논문은 LSTM의 initial memory state와 hidden state를 a의 평균을 input으로 하는 두 개의 MLP 로 estimate한다고 한다.

그럼 이제 LSTM cell 하나에 input으로 들어오는 에 대해 알아보자. 은 바로 전 hidden state이니 제외하고,  t1 시점에서 생성된 caption 을 embedding matrix로 embedding한  dimensional vector이다. 는 맨 처음에 randomly initialize를 한 이후 train 과정에서 update되는 parameter이다. 마지막으로 context vector라고 하는데, 이 context vector는 attention model들에 의해서 결정된다.

Context vector 는 CNN encoder output 와 바로 전 hidden state 에 의해 다음과 같이 결정된다.

먼저 는 time 에서의 weight vector를 의미하며, 는 time 에서의  번째 element 에 해당하는 weight value값이다. 이때 weight란, 우리가 주어진 annotation (CNN의 output) 중에서 어느 location에 focus를 맞출 것인지, 혹은 어떤 것이 중요하지 않은지를 결정하는 값으로, 모델에서 ‘attention’ 개념이 적용된 부분이다. 위의 식에서 알 수 있듯, softmax로 정의가 되기 때문에, weight 의 element-wise summation은 1이다. attention model이라는 것으로, weight vector 를 계산하기 위한 모델이며, 이 논문은 이 모델을 hard와 soft 두 가지로 정의하였다.  function은 주어진 와 그것의 weight vector 를 사용해 z^t를 계산하기 위한 function이다. 정리해보면 다음과 같다.

  • : 의 weight vector로, 어디에 ‘attend’ 할지 결정하는 값. 모두 더하면 1.
  • :  을 사용해 weight vector 를 계산하기 위한 attention model.
  • :  를 받아 를 계산하는 mechanism

Stochastic “Hard” Attention

“Hard” attention은 stochastic mechanism이며, reinforcement learning으로 train할 수 있다. Hard attention model은 매 iteration마다 데이터를 sampling을 해야하고, reinforcement learning과 neural network 부분이 분리되어있어 end-to-end learning이 아니라는 단점이 있다.

Deterministic “Soft” Attention

“Soft” attention은 deterministic machanism으로, standard back-propagation 방법으로 train할 수 있기 때문에 전체 모델이 end-to-end로 learning된다. Soft attention model은 hard attention model의 approximation model이라고 생각하면 된다.

참고자료 : http://sanghyukchun.github.io/93/

Leave a Reply

Your email address will not be published. Required fields are marked *