DevelopHyun

Data Science & Algorith with Computer Science

BiDAF[1] Bidirectional Attention Flow for Machine Comprehension(2016) - Review

23 Feb 2018 » deeplearning, rnn, lstm, attention, nlp, paperreview

1. Abstract

  • MC(Machine Comprehension) : answering a query about a given context paragraph
    • 문장(context)의 흐름을 이해하고, 주어진 문장(context)에서 질문(query)에 대답하는 것
    • query와 context의 복잡한 상호관계를 이해해야함
    • ex) Context : 현우는 동영이에게 1000원을 줬다. 동영이는 우정이에게 다시 1000원을 줬다.
    • ex) Query : 동영이가 가진 돈은?
  • 최근에 Attention 모델이 MC에 사용되기 시작함
    • 문맥의 작은 부분에 집중 가능하며, 그 정보를 fixed-size vector로 표현
  • BiDAF : Bi-Directional Attention Flow
    • multi-stage hierarchical process
    • context를 요약하지않고 query-aware context vector를 찾아내는 방식
    • query의 단어마다 필요로하는 context의 정보가 다르므로, 이것을 세분화하여 query vector에 제공
    • 기존 attention 모델보다 query와 context의 상호작용이 강해짐
  • query-aware context vector로 context summarization 대체
    • context가 query와 연관지어져 query에 필요한 특성을 반영한 vector
    • 정보의 손실을 방지

2. Introduction

  • Attention mechanism은 target의 context paragraph를 잘 이해하게 해준다.
  • Attention mechanism이 과거에 가졌던 특징
    • context를 fixed-size vector로 요약하여 그로부터 attention weight 계산(문맥정보에서 추출)
    • previous hidden state가 attention을 계산하는데 사용되므로, previous attention이 반영됨
    • uni-directional
  • BiDAF
    • hierarchical multi-stage architecture
    • context를 세분화
    • char/word/contextual embedding 사용

2.1 BiDAF의 장점

  1. attention layer가 문맥을 fixed-size vector로 요약하는 것으로 사용되지 않음
    • 이전 layer에서 계산된 attended vector를 subsequent model로 flow하게 해줌
    • previous time step에서 생성되었던 attention은 현재 attention에 영향을 주지 않고, subsequent model(Decoder)을 통하여 flow
    • 이 방법을 통해 요약으로 인한 정보손실이 줄어들게 됨
  2. memory-less attention
    • time-step마다 attention을 계산하여 이전 attention layers를 사용하지않음
    • modeling layer와 attention layer의 분업을 유도
    • 따라서, 현재 time step에서 query와 context의 attention을 학습하는 것에 집중
    • 또한, 이전의 잘못된 attention의 영향을 받지 않게 됨
  3. bi-directional
    • context와 query가 충분히 정보를 교환가능하다.

3. Model

model

  • 6개의 layer로 이루어진 hierarchical multi-stage process

3.1 Character Embedding Layer

  • charCNN을 이용하여 word를 vector로 만들어줌
  • character에 ID vector를 부여하고 CNN에 넣어서 전체적인 모델과 함께 학습.
  • CNN output을 pooling으로 차원을 줄여 embedding으로 사용
  • dimension으로 embedding

3.2 Word Embedding Layer

  • pre-trained word embedding model러 word를 vector로 만들어줌
  • 논문에서는 GloVe 사용
  • dimension으로 embedding

3.3 Contextual Embedding Layer

  • char embedding과 word embedding을 concatenate한 후 2 layer highway network를 통과시킴
  • word 주변의 contextual cues(문맥적 단서)를 사용하여 단어의 embedding을 재정의
  • BLSTM을 통해 주변 문맥을 파악할 수 있게 함
    • forward, backward output을 concatenate하므로 dimension =
  • = #context words, = #query words
  • = Context의 context matrix, = Query의 context matrix where
  • matrix에 vector가 행으로 쌓인 것이 아니라 열로 쌓인 것을 주의, 번째 열 = 번째 단어

3.4 Attention Flow Layer

  • query와 context vector를 연결시키고, 각 단어마다 문맥 속의 query-aware feature vectors를 만듦
  • context vector와 query를 interaction시켜, context에서 query에 대한 답이 될 수 있는 특징들을 추출
  • 즉, Attention Flow Layer는 context와 query의 정보를 서로 연결한다.
    • ex) Context : 사자가 동물원에 있다.
    • ex) Query : 여기엔 무슨 동물이 있나?
    • ex) 위의 문장에서 ‘동물원~여기’, ‘사자~동물’을 연결시키는 역할
  • 이전과는 다르게, query와 context를 single feature vectors로 요약하는 것에 사용되지 않음
    • 요약을 통한 정보손실을 방지할 수 있음
    • query-aware vector
  • previous time step에서 생성되었던 attention은 현재 attention에 영향을 주지 않고, subsequent model(Decoder)을 통하여 flow
    • 기존의 attention model에서는 previous state를 attention 계산에 포함하므로 previous attention이 자동으로 포함됨
    • BiDAF에서는 context와 query의 similarity로만 계산
    • previous attention은 BLSTM으로 구성된 Decoder로만 서로 다른 time step에 전달됨
  • bi-direction으로 attention계산 : Context2Query, Query2Context
    • context와 query의 정보교환을 도움

3.4.1 similarity matrix

  • context와 query가 공유
  • similarity matrix = where
    • 는 t-th context word와 j-th query word의 similarity 의미
    • = context의 t번째 word vector, = query의 j번째 word vector
    • =
    • = a trainable scalar function, similarity를 encoding하는 역할
    • = trainable weight vector, where

3.4.2 Context2Query Attention

c2q

  • query words 중에서 어떤 query word가 각각의 context word와 가장 관계가 있는지 signify
  • =
    • = t-th context word와 query word들의 similarity를 의미
    • t-th context word와 query word의 attention weight
    • for all t
    • similarity 에 softmax를 취해줬으므로 유사성이 큰 weight만 값이 커지게 됨
  • attended query vector = , where
    • j-th query word에 t-th context와의 attention weight를 곱하는 것
    • context가 총 개의 단어이므로,
  • 는 유사성이 큰 것만 값이 크므로, 모든 쿼리의 단어들에 weight를 곱해서 더할 경우 는 유사성이 큰 query의 단어들만 반영이 됨
    • 즉, t-th context word 입장에서 유사성이 높은 query의 특성을 알게 됨
    • 따라서, 는 context 전체의 attended query vector를 담고 있음
    • t-th context word가 어떤 query word와 가까운지를 알려줌
    • t-th context word를 유사성이 높은 query word로 표현함

3.4.3 Query2Context Attention

q2c

  • context words 중에서 어떤 것이 각각의 query word와 가장 관계 있는지 signify
    • 따라서, query에 대답하는 것에서 중요한 역할
  • = , where
    • : 각 row에서 가장 큰 값을 뽑아냄
    • softmax를 취해줬으므로 에서 값이 큰 만 살아남음
    • 즉, 각 context word마다 가장 query words중에서 similarity가 큰 항만 뽑히게 되고, 여기에 softmax를 취해주므로 상대적으로 더 query와 상관있는 context word만 남게 된다.
  • attended context vector =
    • weight 를 곱해서 값이 더해지면, query와 similarity가 큰 t-th context word만 값이 더해짐
    • similarity가 큰 context word만 살아남게 되므로 query 입장에서 중요한 word만 살아남게 됨
    • context에서 가장 중요한 vector의 가중합을 의미
  • 개 나열하여

3.4.4 query-aware representation of each context word

  • =
  • = t-th context vector
    • .
  • =

3.5 Modeling Layer

  • RNN을 통하여 context scan
  • 위에서 구한 가 input
  • query와 context word의 interaction을 파악
  • BLSTM 사용

3.6 Output Layer

  • query에 대한 answer을 output
  • 질문에 대한 대답으로 paragraph의 sub-phrase를 찾아야함
  • paragraph안에 있는 start, end의 indices 를 predict 해서 phrase를 찾음
  • =
  • =
  • 는 각각 LSTM의 forward, backward output

3.7 Training

  • loss : sum of negative pobalites of true start and end indices s by the predicted distributions
    • =
    • = training weights
    • = k-th value of vector P

3.8 Test

  • The answer span with maximum value of

  • Machine comprehension
  • Visual question answering

5. Question Answering Experiment

result1

  • Dataset : SQuAD
  • Ensemble로 사용한 것이 제일 성능이 좋았다.

5.1 Visualization

result2 result3

  • contextual embedding layer가 단어의 사용을 좀 더 잘 구별했다.

5.2 Discussion

result4

  • 어떤 Query에 어떤 Context vector가 담겼는지를 보여줌

5.3 Error Analysis

  • 50% : imprecise boundaries of the answers
  • 28% : syntactic complication/ambiguity
  • 14% : paraphrase problems
  • 4% : require external knowledge
  • 2% : need multiple sentences to answer
  • 2% : mistake during tokenization

6. Cloze Test Experiment

result5


7. Conclusion

  • ablation analysis에서 확인했듯이, model의 구성요소가 모두 중요하다.

8. Reference