Bert-paper reading

論文原文:https://arxiv.org/abs/1810.04805
代碼實現:https://github.com/google-research/bert
按照原文結構記錄總結

#1.Introduction
elmo = feature_based approach,雙層雙向LSTM
GPT = fine-tuning approach,transformer decoder
缺點:
這兩個模型left_to_right or right_to_left都是單向的contextional embedding
bert: masked language model; 通過mask來獲得其上下文相關的向量表達
備註:
ELMO和GPT是bert模型的基礎

#2. Related work

#3.Bert
3.1 pretraining
兩種訓練方式:
masked LM [masked]用作於預測的單詞 ; next sentence prediction(NSP)
3.2 fine-tuning
bert可以用來解決四種類型的任務
1.句子分類
[CLS]特殊標註在句子開頭,其最終的向量表達來做爲整個句子的表達。[CLS]向量通過MLP進行分類判斷
2.Token分類
類似任務1,不過每個Token的向量表達,分別通過MLP進行分類判斷
3.推理
兩個句子的分類,[CLS]作爲句子開頭,[SEP]作爲兩個句子的分割符號。類似任務1,[CLS]是任務分類的向量表達
4.QA問答
後續總結…

#4.Reslut
略過

#5.參考引用
1.https://github.com/NLP-LOVE/ML-NLP/tree/master/NLP/16.8%20BERT
2.李宏毅Bert https://www.bilibili.com/video/av64570585/
3.bert classification,text match等等實現 https://github.com/Jiakui/awesome-bert
4.bert代碼分析https://cloud.tencent.com/developer/article/1454853
5.bert代碼分析https://zhuanlan.zhihu.com/p/58471554

#6.代碼分析
https://github.com/google-research/bert
6.1 pre-training
通過masked_LM; next_sentence_prediction來訓練bert; tokenization.py,create_pretraining_data.py,run_pretraining.py
估計不會從頭訓練bert吧,代碼分析跳過,後續再看吧
https://zhuanlan.zhihu.com/p/70230267

6.2 fine-tuning
1.modeling.py
attention_layer()其中from是query,to是key&value
embedding_postprocessor() positional_embedding,那麼token-type-embeeding如何添加?
create_attention_mask_from_input_mask() 兩個句子對的輸入如何計算mask呢?
2.optimizer.py
AdmaWweightDecay,正確使用adam+L2正則的損失函數==>lazyadamW

3.file_based_input_fn_builder() 實現estimator input_fn
4.create_model() 實現model
5.model_fn_builder() 實現estimator model_fn

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章