introduction: word representaiton
Local representation vs. Distributed representation
Local: one-hot encoding
Distributed: continuous한 요소들의 벡터로 표현
(vectors in a continuous vector space)
downstream task란?
아래그림에서 taget task를 뜻함
fine-tuning approach에서 각 task별 사용하는 방법들
예를들어 NLI(문장관계분석)을 하려면 2문장 가운데, 구분자를 넣어줌
(전체 문장 corpus에 구분자를 넣어준다는 뜻)
BERT(Bidirectional Encoder Representations from Transformers)
양방향으로 정보를 읽어오기위해 고려할 수 있는 2가지 모델
1. Masked Language task (약 12~15%만 masking 시킴)
2. Next Sentence Prediction task(NSP): 다음에 나올 문장으로 적절한 문장 찾기
→ 이 두 방법이 단순히 left-to-right 으로 학습하는 것보다 더 좋은 성능을 보임
Bert의 기본모형
12개의 encoder layer를 쌓아서
768차원의 input으로
12개의 multihead attention을 사용
** multihead attention이란 한 단어를 12개의 관점에서 학습을 시키는 것임
(학습시킬때 bert small을 통해 빠르게 학습시키기 좋음)
BERT의 input
시작할때는 꼭 [CLS]토큰을, 문장이 끝날 때는 [SEP](seperator) 토큰을 넣어줌
Segment embedding은 input 순서를 나타내 주는 것임
각각 하나의 토큰 당 768차원임
Huggingface transformers library
- BERT에서 사용하는 토큰: word piece
- Auto Class: bert-base-uncased
→ bert를 기본으로하고 모든 문자를 소문자화 시켜주는 모델임
→ 사용방법:
model = AutoModel.from_pretrained('bert-base-cased', use_fast=True)
** use_fast=True로 하면 조금 빠르게 분석할 수 있음
tokenizer = AutoTokenizer.from_pretrained('bert-base-cased')
- Pipelines: huggingface에서 모델 틀만 제공해주는데, pipeline을 통해
task별 학습된 모델과 parameter등을 전달 받을 수 있음
→ 사용방법(masking task):
> unmasker = pipeline('fill-mask', model='bert-base-uncased')
> unmasker("Hello I'm a [MASK] model.")
'IT > 자연어분석' 카테고리의 다른 글
BERT1 (0) | 2022.05.26 |
---|---|
LSTM and Sequential Labeling (0) | 2022.05.25 |
Word Vector and Word embedding (0) | 2022.05.06 |
[자연어]Statistical Parsing (0) | 2022.04.20 |
[자연어]Part of Speech Tagging, Sequence Labeling, HMM (0) | 2022.04.08 |