본문 바로가기
Deep Learning/논문정리

Deep Contextualized Word Representation, NAACL 2018 (ELMO 논문 리뷰)

by 대소기 2022. 4. 29.

 

 

 

 

ELMO 논문 : https://arxiv.org/pdf/1802.05365.pdf

 

 

1. Introduction

 

Challenges

* Pre-Trained 모델을 사용하여 고품질의 word representation을 얻는 것은 다음 두 가지 challenge 때문에 어려움.

 1) 단어를 사용할 때의 복잡한 특성(syntax, semantics)

 2) 언어적 맥락에 따라 다양한 단어들의 사용법

 

ELMo(Embeddings form Language Models) Representation 소개

* 본 논문에서는 위 challenge들을 극복하는 Deep Contextualized word representation을 소개함. 소개할 방법은 existing model들에 쉽게 적용 가능함.

* 본 논문에서 제시하는 representation은 기존 embedding 방식과는 달리, 각 토큰에 입력 문장 전체에 대한 정보가 들어있다는 점이 다르다(각 representation은 입력 seuqence의 함수임).

* ELMo representation 내부의 bidirectional LSTM들의 출력들을 linear combination하여 생성한다.

* higher level의 lstm states들은 단어의 맥락적인 의미를 담는다.  ->  supervised word sense ambiguation task에서 사용 가능

* lower level의 lstm staes들은 syntax  ->  part-of-speech tagging task(품사를 식별하여 태깅하는 task)

* 모델은 이 두 가지를 모두 사용하기 때문에 각 end task에 맞는 semi-supervision을 선택할 수 있다는 장점이 있다.

 

 

2. Related Work

 

* 기존의 work들은 context에 독립적인(context 정보를 담지못하는) representation만을 제안했다.

* 연구자들은 이러한 traditional word vector들의 단점을 보완하기 위해 여러 방법들을 사용해왔다.

   1) subword information을 통해 의미를 풍부성을 높임

   2) 각 단어별로 seperate된 vector를 학습(단어당 하나의 벡터가 아닌 맥락에 따른 여러 개의 벡터를 훈련시킴)

   등등

 

 

3. ELMo : Embeddings form Lanugage Models

 

* 기존의 word embedding들과 달리 ELMo word representation은 input sequence의 함수이다(input sequence 전체 맥락의 정보를 담고 있다).

* word representation은 가장 윗 layer의 two-layer biLMs with character convolution에 있는 각 layer 별 state들을 linear combination하여 산출한다.

* 이 과정 덕분에 biLM이 대규모로 훈련되고, 기존의 NLP architecture들과 쉽게 결합되는 semi-supervised learning이 가능해진다.

 

 

3.1 Bidirectional Language Models

 

* ELMo에 사용되는 biLM은 bidirectional multi layer LSTM으로 구성된다. bidirectional multi layer LSTM은 forward multi layer LSTM과 backward multi layer LSTM의 결합으로 이뤄진다. 

* 먼저 forward model을 살펴보고, backward model을 살펴보자.

 

 

3.1.1) Forward Model

* 위와 같이 N개의 token으로 이뤄진 sequence가 주어졌다고 가정해보자.

* forward model은 k < N 번째의 token의 출현 확률을 모델링하기 위해서 첫 번째부터 k번째까지의 token을 사용하여 위와 같이 계산한다.

* 최근 SOTA를 기록하고 있는 NNLM들은 context-independent(context의 정보를 담고 있지 않은)한 token representation (token embeddings나 CNN을 사용해서) $x_k^{LM}$을 계산한다. 그리고 해당 representation을 L개의 LSTM layer를 통과시키는 방법을 사용한다.

* 각 position k(혹은 timestep)에서 LSTM layer의 output은 context-dependent(context의 정보를 담고있는) representation $\vec{h_{k, j}^{LM}}, j=1,...,L$이 된다.

* 각 position k에서의 top LSTM layer의 output은 다음 token $t_{k+1}$을 예측하기 위해 사용된다. 이 때 예측은 softmax layer를 거치며 이뤄진다.

* 정리하자면 각 position k에서의 LSTM layer들의 output들은 k번째 input의 representation을 만들기 위해 사용되고, position k에서의 top LSTM layer의 output은 softmax layer를 거쳐 k+1번째의 input token을 예측하기 위해 사용된다.

 

 

3.1.2) Backward Model

 

* Backward model은 forward model과 동일한 구조로 되어있지만, input seuqence가 reverse되어 있다는 점만 다르다. 때문에 toekn k를 예측하기 위해 k+1 ~ N번째 까지의 token(k보다 뒤에 등장하는 단어들)이 사용된다.

* input sequence가 reverse되어 있는 것만 고려해주면, k번재 token의 representation을 생성하는 과정이나, k-1번째 token을 예측하기 위해 position k의 top layer의 output을 사용하는 것 등은 동일하다.

 

 

3.1.3) biLM

 

* forward model과 backward model의 log likelihood를 결합해 최대화 함으로서 biLM의 log likelihood를 구할 수 있다.

* 이 때, 각 model의 parameter들은 다음과 같이 처리한다.

1) 각 forward model, backward model의 token representation의 parameter $\Theta_x^{forward}$와 $\Theta_x^{forward}$를 $\Theta_x$로 tie하고, softmax layer의 paremeter $\Theta_s^{forward}$와 $\Theta_s^{backward}$를 $\Theta_s$fh tie한다.

2) 각 forward, backward의 LSTM layer parameter $\vec{\Theta}_{LSTM}$, $\overleftarrow{\Theta}_{LSTM}$

  

 

3.2 ELMo

 

3.2.1) BiLM의 representation

* 각 position k에서 biLM은 2L+1개의 representation을 생성한다. forward model에서 L개의 layer의 output, backward model에서 L개의 layer의 output, 최초 단어 vector embedding $x_k^{LM}$ 1개를 모두 더하면 2L+1개의 representation을 얻게 된다.

* 그리고 forward, backward model들의 각 layer별 representation을 합쳐 $h_{k,j}^{LM}, j=0,...,L$을 만들어낸다. 여기서 $h_{k,0}^{LM}$은 token layer이다.

* 논문에는 생략되어 있지만, 보통 biLM을 사용할 때 각 layer별 representation은 forward model, bacakward model의 representation을 concatenate하여 생성한다. 

 

3.2.2) Layer Collapse

 

 

* downstream task를 위해 fine-tuning할 때, concatenated representation $h_{k,j}^{LM}$ 은 j=1~L까지의 layer를 붕괴시켜 하나의 벡터로 합쳐 사용해야 한다. 말이 조금 어려운데, 쉽게 말해 position k에서의 각 layer별 output들을 linear combination을 통해 하나의 벡터로 합쳐주는 것이다.

* position k에서의 representation은 vectr $R_k$로 합쳐진다. linear combination 과정에서 각 벡터에 곱해지는 parameter $s_j^{task}$는 task-specific한 softmax-normalized weights이고, 결과 벡터에 마지막에 곱해지는 $\gamma^{task}$는 scaling해주는 역할을 하며, 이 또한 task-specific한 prameter이다. 이 $\gamma^{task}$의 기능에 대한 부분은 뒷 파트에서 또 자세히 다룬다.

 

3.2.3) Layer Normalization

* biLM의 layer별 activation value의 분포는 각각 다르기 때문에 layer normalization을 사용하는 것도 좋다.

 

 

 

3.3 Using biLMs for supervised NLP tasks

 

* 지금까지 ELMo의 biLM 구조에 대해 알아보았다. NLP architecture에 pre-trained biLM을 사용하는 것 만으로도 논문에서는 엄청난 성능 향상을 이뤄냈다.

* 특정 task를 위한 NLP architecture에 어떻게 pre-trained biLM을 적용할 수 있는지 살펴보자.

 

 

NLP architecture에 biLM적용하기

* NLP model의 구조는 대부분 비슷하다. lower layer에서는 pre-trained word embedding이나, character-based representations를 통해 input sequence에 있는 token들을 context-independent한 representation으로 $x_k$로 변환한다. 이후에 있는 layer(biRNN, CNN, FFNN 등)를 거치며 이 context-independent representation은 context-dependent한 representation으로 변화된다.

 

step1)

* 기본적인 pre-trained embedding을 통과한 vector $x_k$와, ELMo를 통과한 ELMo vector $ELMo_k^{task}$를 concatenate한다.

 

step2)

* step1의 concatenated vector를 task RNN에 input으로 집어넣는다.

 

SNLI, SQuAD에 적용하기

* SNLI 데이터셋을 사용한 자연어 추론 task나, SQuAD 데이터셋을 사용한 QA task의 경우 NLP architecture에 데이터를 집어넣기 전 단계에서만 ELMo를 사용하는 것이 아니라, NLP archtecture의 출력을 다시 EMLo에 집어넣는 방식을 사용했다.

* 물론 이 때 출력부분의 EMLo의 task specific linear weights $s_j^{task}$는 입력부분의 $s_j^{task}$와는 다르게 적용하였다.

 

 

ELMo의 장점

* NLP architecture에 ELMo를 적용할 때 기존 architecture의 구조를 거의 건들이지 않기 때문에(입력, 출력 부분에서만 ELMo 적용) ELMo를 임의의 architecture에 적용하기 좋다.

 

 

성능을 높이는 추가적인 방법

* 적절한 rate의 dropout을 ELMo에 적용

* weights에 $\lambda || w ||_2^2$을 더함으로서(L2 regularization) weight에 규제를 가함.

* 이를 통해 inductive bias를 부과해 ELMo의 weights를 모든 biLM layer의 average에 가깝게 유지할 수 있음.

 

 

 

 

3.4 Pre-trained bidirectional language model architecture

 

Pre-trained biLM Model Architecture 설명

* character-based input representation을 사용하면서 LM의 perpelxity와 downstream task를 위한 computational requirements 간의 balance를 맞추기 위해 CNN-BIG LSTM model( 관련 논문 : https://arxiv.org/pdf/1602.02410.pdf)의 single best model의 embedding과 hidden dimensions를 절반으로 하여 architecture에 적용하였다. 그 내용은 아래와 같다.

 

   ELMo의 embedding 구조

   1) 4096개의 units, 512차원의 projections(embedding vector의 출력차원)의 층이 2개인 biLSTM layer

   2) 첫 번째 layer와 두 번째 layer간의 Residual Connection

  

   Context insensitive embedding 구조

   1) 2048 character n-gram convolutional filters

   2) 2개의 highway layers(관련 논문 : https://papers.nips.cc/paper/2015/file/215a71a12769b056c3c32e7299f1c5ed-Paper.pdf)

   3) 512차원의 linear projection

 

* 위 두 개의 embedding model을 통해 입력 token에 대해 3가지의 representation(biLM의 forward, backward represenation, context insensitive embedding의 representation)을 제공하게 된다.

 

 

Pretraining 및 결과

* 10 epochs on 1B word

* average forward-backward perplexity 39.7(backward peplexity가 살짝 더 낮았음)

* CNN- Big LSTM peplexity 30.0

* downstream task에 맞게 domain specific한 데이터로 fine-tuning을 하는 것이 성능이 더 좋았음(perplexity down, performance up).

 

 

 

 4. Evaluation

* ELMo를 추가하는 것 만으로 SOTA 달성

* Error reduced ranging form 6-20%

 

Question Answering

* SQuAD 사용

* Baseline model : BiDAF(Bidirectional Attention Flow model), 관련논문 : https://arxiv.org/abs/1611.01603

 

Textual Entailment

* SNLI 사용

* Baseline model : ESIM

 

Semantic role labeling

* 생략

Coreference resolution

* 생략

Named Entity Extraction

* 생략

Semantic Analysis

* 생략

 

 

 

5. Analysis

 

* section 5에서는 ablation analysis 결과를 다룬다.

* ablation analysis의 정확한 의미를 잘 정리해놓은 블로그가 있어서 잠깐 소개한다.

https://fintecuriosity-11.tistory.com/73

 

[데이터 사이언스]"Ablation study"란 무엇인가?

데이터 사이언스에 관련을 가지게 되면서 머신러닝, 딥러닝에 관한 연구, 논문과 수업들에서는 이해가 안가는 단어들이 한,두가지 아니였습니다. 그래서 항상 공부를 하며 모르는 단어의 어원

fintecuriosity-11.tistory.com

 

 

5.1 Alternate layer weighting schemes

* representation들을 합칠 때 위와 같은 방법을 소개한 바 있다. 하지만, 이 방법 외에도 마지막 layer의 representation만 사용하는 등의 방법도 사용 가능하다.

* 그리고 앞서 추가적으로 성능을 높이기 위해 L2 regularization을 사용할 수 있다고 했었는데, 이 때 $\lambda$ 값이 매우 중요하다. 당연한 얘기지만 $\lambda$ 값이 클 수록 더 강력한 규제로 인해 weight들이 평균에 가깝게 분포하게 된다.

 

 *먼저 representation 사용 방법에 대해 실험한 결과를 보자. baseline은 3절에서 설명했던 방법으로 representation을 linear combination 하여 사용한 것이고 Last only는 마지막 layer의 representation만 사용한 결과이다. 오히려 위 QA, TE, SRL task들에서는 ELMo를 마지막 layer만 사용하는 것이 더 성능이 좋았다.

* 두 번째로 L2 regularization시 $\lambda$ 값은 더 작게 하는 것이 미세한 성능 향상을 보여줬다. 다만, NER task와 같이 작은 training set에서는 $\lambda$값의 영향을 크게 받지 않았다.

 

 

 

5.2 Where to include ELMo?

 

* 기본적으로 ELMo를 lowest layer에 적용하는 방법을 사용했지만, 위 몇 task에서는 output layer에도 적용하는 것이 성능이 더 높았다.

 

 

5.3 What information is captured by the biLM's representations?

* biLM을 사용하는 것은 언어의 다의성으로 인한 representation의 ambiguity를 없애준다.

* GloVe를 사용할 경우 Nearest Neighbor들이 스포츠와 관련된 단어들이 대부분이지만, biLM의 경우 context의 의미를 반영한 것들이 Nearest Neighbors인 것을 볼 수 있다.

* 이렇게 context에 대한 정보를 represenation에 담을 수 있다는 것 외에도 

 

 

word sense disambiguation(단어 의미 중의성 해소)

 

* 1-nearest neighbor approach를 사용해서 biLM representation을 통해 target word의 의미를 예측할 수 있었다. 과정은 다음과 같다.

 1) SemCor 3.0에 있는 모든 단어들의 representation을 계산한다.

 2) 각 의미별 representation들을 모두 average한다.

 3) biLM을 사용해 target word의 representation을 계산하고, KNN방식으로 이 representation과 비슷한 의미를 가진 단어를 계산하였다.

 

* 이렇게 biLM을 사용해 WSD task를 수행한 결과 biLM second layer는 SOTA 성능과 비슷한 수준인 것으로 밝혀졌다.

 

POS tagging

 

* POS tagging에서도 역시 좋은 성능을 보였다.

 

 

Implications for supervised tasks

 

* 결론적으로 biLM 의 각 layer들은 다른 정보의 representation을 담고 있고, 기존의 모델들에 transferable하다고 볼 수 있다.

 

 

5.4 Sample efficiency

* ELMo를 모델에 추가하는 것은 sample efficiency를 향상시킨다.

* SNLI(language infersence task)와 SLR(Sematic Role Labeling) 모두 ELMo를 사용했을 때 더 빠르게 수렴한다.

* 또한, 더 적은 training set을 사용하게 된다.

 

 

5.5 Visualization of learned weights

* 각 task별로 어떤 layer를 favor하는지를 나타낸 자료이다.

 

 

 

 

6. Conclusion

* 여러가지 ablations, controlled experiments들을 통해 biLM layer가 효율적으로 다른 종류의 syntactic, semantic information들을 encode한다는 것을 알 수 있었다.