BERT 는 Google AI Language 에서 발행한 논문이고 아래 링크에서 논문을 확인할 수 있다
https://arxiv.org/abs/1810.04805
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
We introduce a new language representation model called BERT, which stands for Bidirectional Encoder Representations from Transformers. Unlike recent language representation models, BERT is designed to pre-train deep bidirectional representations from unla
arxiv.org
Abstract
We introduce a new language representation model called BERT, which stands for Bidirectional Encoder Representations from Transformers
Abstract 부분에서는 BERT 이름에 대해서 설명을 하고 있다 (자세한건 이따가 정리를 할 것 이다)
그다음 부분에 나오는 부분은
the pre-trained BERT model can be finetuned with just one additional output layer to create state-of-the-art models for a wide range of tasks
BERT는 "단 하나의 output layer를 추가 함을 통해 더 넓은 범위의 일을 커버할 수 있게 된다" (QA , 번역 등등 )
이 부분이 GPT 와 가장 큰 차이이지 않을까 라는 생각이 들고
약간의 BERT에게 경쟁심이 있는 OpenAI가 additional output layer를 하지 않고 zero-shot, few-shot을 강조하는 이유이지 않을까 생각된다
다양한 데이터 셋 GLUE , SQuAD 등등에서 좋은 성능을 보인다고 한다
먼저 다음과 같이
Bidirectional
Encoder
Representations
Transformers
이고 한 단어씩 의미를 분석해 보자
Bidirectional
먼저 이 Bidirectional (양방향)을 논문에서 어떻게 설명하고 있는지 살펴 보자면
BERT is designed to pretrain deep bidirectional representations from unlabeled text by jointly conditioning on both left and right context in all layers
이는 BERT가 Transformer의 Encoder 구조를 차용해와서 가능한 특징으로
2018년에 나온 Decoder를 기반으로하는 GPT 1과 비교를 해보면 이해가 쉽다
GPT 1 :: Unidirection (Left to right context)
in OpenAI GPT, the authors use a left-to-right architecture, where every token can only attend to previous tokens in the self-attention layers of the Transformer
GPT 1 의 경우 left-to-right 즉, 왼쪽에서 오른쪽으로 진행되는 구조이다.
이는 Transformer : Attention Is All You Need 라는 논문에서 해답을 얻을 수 있는데
The “Encoder-Decoder Attention” layer works just like multiheaded self-attention, except it creates its Queries matrix from the layer below it, and takes the Keys and Values matrix from the output of the encoder stack.
GPT 1은 Transformer의 Decoder 부분을 차용하였고
위의 영상과 같이 Decoder 가 Output을 만들 때 Encoder에서 받은 Keys, Values matrix와
Previous Output (The layer below it)을 통해 만든 Queries matrix를 이용하기 때문에
left to right의 구조를 가질 수 밖에 없다
이에 반면해 BERT의 경우
"masked language model"을 이용하기 때문에 Bidirectional 하다고 할 수 있고 이는 Chapter 3에서 설명을 한다
Encoder
위에서도 언급했듯이 BERT는 Transformer의 Encoder 를 통해 만들어 졌다
Encoder의 Muti Head Attention을 살펴 보면 single head를 여러 개 붙이는 과정은 생략하고 앞부분
single head attention의 출력 z0를 만들어 낼때 다음과 같은 연산
Transformer에 관해 공부를 하고 있다면 다음 연산 과정이 중요하지만 지금은
z1 을 만들어 내기 위해 x1 만 고려 하는 것이 아닌 x2에 의해 나온 k2, v2 등을 이용한다는 점
즉, 문장의 모든 단어를 고려하여 출력 z1 이 나온다는 점만 생각하고 넘어가면 된다
이렇기 때문에 Bidirectional 구조도 가능하다
Representation
NLP에서 사용하는 Representation 이라는 말의 의미가 무엇일까? 라는 질문에
아래 블로그를 참고하면 답을 조금 얻을 수 있다
https://colah.github.io/posts/2014-07-NLP-RNNs-Representations/
Deep Learning, NLP, and Representations - colah's blog
Introduction In the last few years, deep neural networks have dominated pattern recognition. They blew the previous state of the art out of the water for many computer vision tasks. Voice recognition is also moving that way. But despite the results, we hav
colah.github.io
they learn better ways to represent data, automatically. Representing data well, in turn, seems to be essential to success at many machine learning problems. Word embeddings are just a particularly striking example of learning a representation.
즉, NLP에서 Representation이라는 의미는 어떻게 자연어의 의미를 함축하냐의 의미를 담는다
Bert를 엄청 나만의 언어로 바꿔서 표현해보자면
BERT : Bidirectional하게 관계를 분석,표현(Representation)하는 방법으로 TransFormer의 Encoder 부분을 가져와서 사용한 모델
이라 해석을 해볼 수 있다
Transformer
Transformer의 경우 가볍게 설명이 힘들고 매우 중요한 개념이기 때문에 추후에
Attention Is All you need 눈문 분석 혹은
아래의 링크 Transformer에 대하여 설명한 부분을 첨부하고 넘기겠다
[DL Basic] Transformer (Attemtion is All You Need).2017
Tranformer는 엄밀하게 말하면 앞에서 연결되는 RNN, LSTM, GRU와는 좀 다른 방법으로 접근한다 -> 해결하고자 하는 것은 동일함 왜 Sequential modeling이 다루기 어려울까? 우리의 일상생활을 생각해보자
aisj.tistory.com
1. Introduction
Many natural language processing taks include sentence-level tasks such as natural language inference (Bowman et al., 2015; Williams et al., 2018) and paraphrasing (Dolan and Brockett, 2005), which aim to predict the relationships between sentences by analyzing them holistically, as well as token-level tasks such as named entity recognition and question answering, where models are required to produce fine-grained output at the token level
이를 문장 전체로 이해하기는 헷갈릴 수 있기 때문에 의역을 해보자면
NLP 즉, 자연어 처리를 한다는 것은 두가지 level 에서 풀어야하는 특징이 있다
- Sentence level
- Token level
Sentence Level
aim to predict the relationships between sentences by analyzing them holistically
Sentence level 의 task 는 자연어 추론, 의역 등이 있는데
이는 holistically(전체적으로) 하게 문장을 분석하는 것이다
holistically 하다 라는 뜻은 다음과 같이
"by analyzing them holistically" refers to the approach of considering the entire context of a sentence or document, rather than just looking at individual words or phrases in isolation.
해석을 해볼 수 있다.
즉, 단어 전체를 고려하여서 (아마도 문맥) 분석을 하는 것이 sentence level 의 task 이다
Token Level
model are required to produce fine-grained output at the token level
Token level의 task 는 대명사 분석, 질문 답변 등을 예시로 들 수 있는데
이 Task 를 해결하기 위해서는 미세하게 잘 쪼개진 Output을 만들 수 있어야 한다
먼저 다음 문장으로 넘어가기 전에 Down-stream Task의 의미를 Chat-gpt에게 물어본 결과
"downstream tasks" refer to a set of natural language processing (NLP) tasks that can be performed using the pre-trained BERT model. These tasks are called "downstream" because they rely on the outputs (or "representations") of the pre-trained model as input.
즉, BERT는 Pre-trained model을 사용하기 때문에 이 pre-train model을 거치고 나온 output(Representation) 이 들어가는
one-additional output layer 가 할 일이 Downstream Task라고 생각을 한다
논문에 의하면 이 Down stream task에서 Pre-trained model을 이용하는 전략이 두가지라고 한다
- Feature-based
- Fine-tuning
Feature-based
Feature-based의 대표적인 예시는 ELMo 라고 한다
ELMo의 경우는 Uses task-specific architecture을 사용한다고 한다
즉, 작업에 맞춰서 additional Feature를 사용한다고 한다
Fine-tuning
Fine-tuning 의 대표적인 예시는 GPT 라고 한다
GPT의 경우 minimal task-specific parameter를 추가한다음
이 추가된 parameter를 학습함과 동시에 와 모든 Pre-trained parameter를 fine-tunning 한다
이 둘 (ELM0, GPT)의 공통점은
The two approaches share the same objective function during pre-training, where they use unidirectional language models to learn general language representations
둘 다 Unidirectional 하다는 것이다
이게 뭐가 문제일까?
The major limitation is that standard language models are unidirectional, and this limits the choice of architectures that can be used during pre-training.
위에서 말하길 단방향 언어 학습 모델이 pre-training 하는 동안에 선택할 수 있는 구조 선택에 제한이 된다고 하는데
잘.. 이해가 안되니 아래의 GPT로 예시를 들은 부분을 고려하여서 생각을 적어보면
the authors use a left-to right architecture, where every token can only attend to previous tokens in the self-attention layers of the Transformer (Vaswani et al., 2017). Such restrictions are sub-optimal for sentence-level tasks, and could be very harmful when applying fine-tuning based approaches to token-level tasks such as question answering, where it is crucial to incorporate context from both directions.
여기에서 우리는 위에서 왜 두가지 level의 Task가 있다
하나는 Sentence level Task가 있고 또 하나는 Token level Task가 있다고 설명을 하였는지 알 수 있다
Transformer는 어쩔 수 없이 self-attention 과정에서 Previous Token 만 확인 할 수 있는 제약이 있는데
Sentence level Task에서 성능을 보이지만 sub-optimal 즉, 최적의 방법이 아니고
Token level Task (질문에 대한 대답 등)을 수행하기엔 무리가 있다고 한다
-> 내 생각을 말하자면 QA문제 보다는 대명사를 Token 단위 즉, He is cute 에서 He 가 누구를 의미할지 Token 단위로 물어본다면 취약하다는 뜻 같다
이를 해결하기 위해서 Both Direction (즉 Bidirectional)을 가져왔다고 한다
※여기서 자주 언급되는 Fine-tuning은 미세 조정 이라고 생각하면 된다
한마디로 요약을 하자면
BERT 는 어떻게 하면 Fine-tuning을 잘할 수 있을까에 대한 연구라고 생각할 수도 있다
BERT alleviates the previously mentioned unidirectionality constraint by using a “masked language model” (MLM) pre-training objective
※alleviate : 덜다
이 Unidirectionality (단방향)을 어떻게 해결 할 수 있었나면 MLM(masked language model)을 사용하였기 때문이라고 한다
그렇다면 MLM 이란 무엇일까?
MLM (masked language model)
The masked language model randomly masks some of the tokens from the input, and the objective is to predict the original vocabulary id of the masked word based only on its context
이는 무작위로 들어오는 token 들에 대해
예시를 들면 좀 더 쉬운데 "He is a teacher" 이라는 예시가 있다고 하면
다음과 같이 "[MASK] is a teacher" 라고 바꾼다 음 이 [MASK]자리에 들어갈 단어를 context를 이용하여서 유추해내는 model 이다
the MLM objective enables the representation to fuse the left and the right context, which allows us to pretrain a deep bidirectional Transformer. In addition to the masked language model, we also use a “next sentence prediction” task that jointly pre-trains text-pair representations.
※fuse : 퓨전 할때 fuse 이다
이렇게 함으로써 left 와 right 문맥을 전부다 이용하여서 학습을 하고
"Next sentence Prediction" 또한 할 수 있다고 한다
이로써 BERT는 무엇을 보였는가
We show that pre-trained representations reduce the need for many heavily-engineered taskspecific architectures.
Pre-trained representation 을 할 때 그렇게 많은 고도의 작업을 할 필요 없다는 것을 보였다
당장에 Target Task를 목표로 정제된 ELMo보다 성능이 좋다는 것으로 증명했다
심지어 SOTA (state-of-the-art)까지 달성 했다고 한다
(나중에라도 논문을 다시 읽을 때 모든 논문에 있어서 Introduce 부분이 가장 중요하다는 것을 명심하자)
2. Related Work
2.1 Unsupervied Feature-based Approaches
Pre-trained word embeddings are an integral part of modern NLP systems, offering significant improvements over embeddings learned from scratch (Turian et al., 2010).
...
To train sentence representations, prior work has used objectives to rank candidate next sentences (Jernite et al., 2017; Logeswaran and Lee, 2018), left-to-right generation of next sentence words given a representation of the previous sentence (Kiros et al., 2015), or denoising autoencoder derived objectives (Hill et al., 2016). ELMo and its predecessor (Peters et al., 2017
Pre-train된 단어의 Embedding은 현대 NLP 시스템에 중요한 부분이라고 한다
이렇게 문장의 표현을 학습하기 위해 다음과 같이
다음 문장의 후보의 순위를 정하거나
왼쪽에서 오른쪽으로 문자를 생성하거나
오토 인코더로 부터 생긴 noise를 제거하는 등의 시도 들이 있었다
그러고 나서 ELMo에 관해 예시를 들어주는데 (논문 자체가 GPT, ELMo와의 비교가 많다)
<ELMo and Melamud>
ELMo의 경우 "Different Dimension"에 집중을 한다
They extract context-sensitive features from a left-to-right and a right-to-left language model.
The contextual representation of each token is the concatenation of the left-to-right and right-to-left representations.
ELMo는 문맥에 예민한 특징을 추출하기 위해서 '왼쪽에서 오른쪽의 표현'과 '오른쪽에서 왼쪽의 표현'을 합치는 Contextual representation을 만든다.
이 뿐만아니라 Melamud 연구진은
proposed learning contextual representations through a task to predict a single word from both left and right context using LSTMs
LSTM을 이용해서 왼쪽과 오른쪽 Context를 이용하여서 단어를 예측하는 모델을 제안하였다
하지만 이 둘 (ELMo, Melamud) 모두 feature-based 이지만 "Not deeply bidirection" (깊지 않은 양방향)이다
2.2 Unsupervied Fine-tuning Approaches
The first works in this direction only pre-trained word embedding parameters from unlabeled text.
More recently, sentence or document encoders which produce contextual token representations have been
pre-trained from unlabeled text and fine-tuned for a supervised downstream task
Fine-tuning의 첫번째 작업은 레이블이 없는 텍스트로 부터 사전학습된 word embedding parameter를 사용하는 것이였다
이것이 발전하여서 Unlabeld text로 부터 Pre-trained를 진행하고 Supervised Data를 통해서 Fine-tining 하는 방법이 제시가 되었다 -> GPT가 이러한 방식을 선택하였고 좋은 성능을 보였다
"The advantage of these approaches is that few parameters need to be learned from scratch"
이렇게 학습을 진행하면 장점이 밑바닥 부터 학습해야하는 파라미터의 수가 거의 줄어든다는 것이다
2.3 Transfer Learning from Supervised Data
-> Supervised Data로 부터의 전이 학습
※ 전이 학습이란 ? : '한 분야의 문제를 해결하기 위해서 얻은 지식과 정보를 다른 문제를 푸는데 사용하는 방식'
here has also been work showing effective transfer from supervised tasks with large datasets, such as natural language inference (Conneau et al., 2017) and machine translation (McCann et al., 2017). Computer vision research has also demonstrated the importance of transfer learning from large pre-trained models, where an effective recipe is to fine-tune models pre-trained with ImageNe
큰 데이터 셋을 사용하여서 Superviesed Tasks를 수행한다음 전이 학습을 사용하면 좋은 성능을 보여 준다는 것은 이미 보여진 적이 있다고 한다
3. BERT
There are two steps in our framework: pre-training and fine-tuning.
BERT 의 중요한 컨셉 두개는 pre-training 이랑 fine-tunning 이다
During pre-training, the model is trained on unlabeled data over different pre-training tasks
그림에서 볼 수 있듯이 Pre-training task에서는 Unlabled Sentence를 통해 모델을 학습시킨 후
For fine- tuning, the BERT model is first initialized with the pre-trained parameters, and all of the param- eters are fine-tuned using labeled data from the downstream tasks
'Paper Reading' 카테고리의 다른 글
[paper] Transformer 실습을 통해 익히는 Pytorch 기초 (Attention is All you Need) (0) | 2023.08.22 |
---|---|
[Paper] Multi-Concept Customization of Text-to-Image Diffusion (0) | 2023.05.01 |
[Paper] GoogLeNet: Going deeper with convolutions (0) | 2022.10.12 |
[Paper]FaceNet: A Unified Embedding for Face Recognition and Clustering (0) | 2022.09.19 |