본문 바로가기
AI/파이토치(Pytorch)

[Pytorch][BERT] 버트 소스코드 이해_④ BertModel

by Hyen4110 2022. 7. 5.
반응형

[Pytorch][BERT] 버트 소스코드 이해 목차

BERT  📑 BERT Config    
  📑 BERT Tokenizer      
  📑 BERT Model 👀 📑 BERT Input    
    📑 BERT Output    
    📑 BERT Embedding    
    📑 BERT Pooler    
    📑 BERT Enocder 📑 BERT Layer 📑 BERT SelfAttention
        📑 BERT SelfOtput

 

BertModel

 

🎅 BertModel을 통해 데이터가 어떻게 움직일까?

[Step1] BertEmbedding 인코더에 전달할 텍스트 임베딩 생성

 

[Step2] BertEncdoer 텍스트 임베딩을 인코더를 통해 정보 압축

 

[Step3] BertPooler 최종 임베딩 값 반환

 

🎅 각 단계에서 무슨 일이?

1. BertEmbedding

2022.07.06 - [파이토치(Pytorch)] - [Pytorch][BERT] 소스 코드 이해_ ⑤BertEmbedding

 

[Pytorch][BERT] 소스 코드 이해_ ⑤BertEmbedding

1. BertEmbedding 이란? : BertEocder에 들어갈 임베딩 생성 = WordPiece Embedding + Position Embedding + Segment Embedding Embedding 설명 default WordPiece Embedding (=word_embeddings) 실질적인 입력이..

hyen4110.tistory.com

 

2. BertEncoder

2022.09.30 - [파이토치(Pytorch)] - [Pytorch][BERT] 소스 코드 이해_⑤BertEncoder (modeling_bert.py)

 

[Pytorch][BERT] 소스 코드 이해_⑤BertEncoder (modeling_bert.py)

1. BertEncoder init 함수를 보니 많은 BertLayer 로 이루어져있다 ⇒ BertEncoder → BertLayer → BertAttention→ BertSelfAttention class BertEncoder(nn.Module): def __init__(self, config): super().__i..

hyen4110.tistory.com

3. BertPooler

2022.10.28 - [자연어처리(NLP)] - [Pytorch][BERT] 버트 소스코드 이해_⑦ Bert Pooler

 

[Pytorch][BERT] 버트 소스코드 이해_⑦ Bert Pooler

1. BertPooler : 마지막 hidden_state의 첫번째 토큰인 [CLS] 토큰의 embedding을 반환 We "pool" the model by simply taking the hidden state corresponding to the first token. The pooling layer at the end..

hyen4110.tistory.com

 

🎅 BertModel의 input과 ouptput

1. BertModel의 입력값은?

2022.10.28 - [자연어처리(NLP)] - [Pytorch][BERT] 버트 소스코드 이해_⑧ BERT model 입력값

 

[Pytorch][BERT] 버트 소스코드 이해_⑧ BERT model 입력값

1. BertModel 입력값 - BERT 모델을 생성한 후, forward 함수에서 필요한 입력값에 대한 정리 class BertModel(BertPreTrainedModel): def forward( self, input_ids, attention_mask, token_type_ids, position_i..

hyen4110.tistory.com

 

2. BaseModel의 출력값은?

2022.10.28 - [자연어처리(NLP)] - [Pytorch][BERT] 버트 소스코드 이해_⑨ BERT model 출력값

 

[Pytorch][BERT] 버트 소스코드 이해_⑨ BERT model 출력값

BaseModel의 출력값은? class BertModel(BertPreTrainedModel): def forward(...): ........ return BaseModelOutputWithPoolingAndCrossAttentions( last_hidden_state = **sequence_output**, pooler_output = *..

hyen4110.tistory.com

 

반응형

댓글