추가적인 모듈로 Attention을 활용 할 수 있다.
rnn기반의 모델 구조가 앞에서 부터 순차적으로 정보를 읽어주고, 매 time마다 축적해 나아가는데, rnn의 hidden state vector의 dim이 정해져있다는 특성으로 인해 마지막 hidden state vector에 모든 정보를 넣어야한다.
훨씬 이전에 나타났던 정보들은 점차 time이 지나면서 정보가 변질되거나 손실되는 문제가 있다.
Attention을 사용하게 되면 마지막의 hiddnstate vector하나에만 의존하는 것이 아니라 encoder의 각 time hidden state vector를 전체적으로 decoder에 제공해주며, 각 time step에서 필요한 hidden state vector를 우선적으로 제공하여 준다.
Use the attention distribution to take a weighted sum of the encoder hiddn states
The attention ouput mostly contains information the hidden states that received high attention
Concatenate attention output with decoder hidden state, then use to compute 1 as before
학습시 decoder의 입력으로 ground truth, 매 time step마다 올바른 입력만이 주어지는 학습 방법을 Teacher forcing이라고 부른다.
반면, ground truth를 매 time step마다 넣어주는 것이아니라 예측 값이 잘못되었던, 올바르던 넣어주게되는 방식이 Teacher forcing이 아닌 방식이 된다.
실제 사용해을 때에 가까운 방식은 후자가 된다.
전자는 학습이 빠르고 용이하게 되는 방법으로 학습상황에는 적합하지만, 실제 상황에 맞추기에는 후자가 용이하게 된다.
따라서 학습 초기에는 Teacher forcing방법으로 진행하며, 학습이 어느정도 지난 후에 Teacher forcing가 아닌 방법으로 학습을 진행시키면 학습을 잘 이루어 지도록 할수있다.
concat을 이용한 score계산에 대한 수식의 과정
Attention significantly improves NMT performance
Attention solves the bottleneck problem
Attention helps with vanishing gradient problem
Attention provides some interpretability(해석가능성)
앞서 배운 seq2seq모델을 통한 자연어 생성 모델에서 test time에서 보다 좋은 생성결과를 얻을 수있도록 하는 기법
매 time step마다 가장 높은 확률의 단어를 선택해 생성하게 된다.
위와 같이 잘못 단어를 예측할 경우가 발생한다.
이를 어떻게 fix해야할까?
Ideally, we want to find a (length ) translation that maximizes
동시사건에 대한 확률분포 수식을 사용한다.
We could try computing all possible sequences
매 time step마다 하나의 단어만을 고려하는 greedy decoding과 매 time step마다 가능한 모든 조합을 고려하는 Exhausitive search 이 두 사이에 있는 알고리즘.
Core idea : decoder의 매 time step마다 정의해 놓은 어떤 k개의 가지수를 고려하고 time step이 진행되어지더라고 k개를 유지하고 이중 가장확률이 높은 것을 택하는 방법
일반적으로 k(beam size)는 5~10사이의 값으로 설정하게 된다.
Scores are all negative, and a hight score is better
We search for high-scoring hypotheses, tracking the top ones on each step
Beam search is not guaranteed to find a globally optimal solution.
But it is much more efficient than exhaustive search!
In greedy decoding, usually we decode until the model produces a <END>
token.
In beam search decoding, different hypotheses may produce <END>
tokens on different timesteps
<END>
, that hypotheses is completeUsually we continue beam search until:
We have our list of completed hypotheses
How to select the top one with the highest score?
Each hypothesis 𝑦1, … , 𝑦𝑡 on our list has a score
Problem with this : word의 갯수, sequence의 길이가 다를 경우 상대적으로 짧은 경우 hypothesis joint probility 값이 낮을 것이고, 반대의 경우는 높을 것이다.
Fix : Normalize by length
자연어 생성모델에서 그 결과의 품질, 정확도를 평가하는 방법
평균을 구하는 방법으로 아래의 세가지(산술평균, 기하평균, 조화평균)이 있다.
F-measure는 조화평균을 사용한 방법이다.
BiLingual Evaluation Understudy(BLEU)