RoBERTa中文预训练模型:RoBERTa for Chinese
RoBERTa for Chinese, TensorFlow & PyTorch
項目主頁:https://github.com/brightmart/roberta_zh
中文預(yù)訓(xùn)練RoBERTa模型
RoBERTa是BERT的改進(jìn)版,通過改進(jìn)訓(xùn)練任務(wù)和數(shù)據(jù)生成方式、訓(xùn)練更久、使用更大批次、使用更多數(shù)據(jù)等獲得了State of The Art的效果;可以用Bert直接加載。
本項目是用TensorFlow實現(xiàn)了在大規(guī)模中文上RoBERTa的預(yù)訓(xùn)練,也會提供PyTorch的預(yù)訓(xùn)練模型和加載方式。
中文預(yù)訓(xùn)練RoBERTa模型-下載
** 推薦 RoBERTa-zh-Large 通過驗證**
RoBERTa-zh-Large?TensorFlow版本,Bert 直接加載
RoBERTa 24層版訓(xùn)練數(shù)據(jù):30G原始文本,近3億個句子,100億個中文字(token),產(chǎn)生了2.5億個訓(xùn)練數(shù)據(jù)(instance);
覆蓋新聞、社區(qū)問答、多個百科數(shù)據(jù)等。
Roberta_l24_zh_base?TensorFlow版本,Bert 直接加載
24層base版訓(xùn)練數(shù)據(jù):10G文本,包含新聞、社區(qū)問答、多個百科數(shù)據(jù)等。
What is RoBERTa:
A robustly optimized method for pretraining natural language processing (NLP) systems that improves on Bidirectional Encoder Representations from Transformers, or BERT, the self-supervised method released by Google in 2018.RoBERTa, produces state-of-the-art results on the widely used NLP benchmark, General Language Understanding Evaluation (GLUE). The model delivered state-of-the-art performance on the MNLI, QNLI, RTE, STS-B, and RACE tasks and a sizable performance improvement on the GLUE benchmark. With a score of 88.5, RoBERTa reached the top position on the GLUE leaderboard, matching the performance of the previous leader, XLNet-Large.(Introduction from Facebook blog)發(fā)布計劃 Release Plan:
1、24層RoBERTa模型(roberta_l24_zh),使用30G文件訓(xùn)練, 9月8日
2、12層RoBERTa模型(roberta_l12_zh),使用30G文件訓(xùn)練, 9月8日
3、6層RoBERTa模型(roberta_l6_zh), 使用30G文件訓(xùn)練, 9月8日
4、PyTorch版本的模型(roberta_l6_zh_pytorch) 9月8日
5、30G中文語料,預(yù)訓(xùn)練格式,可直接訓(xùn)練(bert,xlent,gpt2) 9月14日或待定
6、測試集測試和效果對比 9月14日
效果測試與對比 Performance
自然語言推斷:XNLI?
注:RoBERTa_l24_zh,只跑了兩次,Performance可能還會提升
Sentence Pair Matching (SPM): LCQMC
?
注:RoBERTa_l24_zh,只跑了一次,目前還不是最佳成績。保存訓(xùn)練輪次和論文一致:
? 處地方,將會很快更新到具體的值
RoBERTa中文版 Chinese Version
本項目所指的中文預(yù)訓(xùn)練RoBERTa模型只指按照RoBERTa論文主要精神訓(xùn)練的模型。包括:
1、數(shù)據(jù)生成方式和任務(wù)改進(jìn):取消下一個句子預(yù)測,并且數(shù)據(jù)連續(xù)從一個文檔中獲得(見:Model Input Format and Next Sentence Prediction,DOC-SENTENCES)2、更大更多樣性的數(shù)據(jù):使用30G中文訓(xùn)練,包含3億個句子,100億個字(即token)。由新聞、社區(qū)討論、多個百科,包羅萬象,覆蓋數(shù)十萬個主題,所以數(shù)據(jù)具有多樣性(為了更有多樣性,可以可以加入網(wǎng)絡(luò)書籍、小說、故事類文學(xué)、微博等)。3、訓(xùn)練更久:總共訓(xùn)練了近20萬,總共見過近16億個訓(xùn)練數(shù)據(jù)(instance); 在Cloud TPU v3-256 上訓(xùn)練了24小時,相當(dāng)于在TPU v3-8(128G顯存)上需要訓(xùn)練一個月。4、更大批次:使用了超大(8k)的批次batch size。5、調(diào)整優(yōu)化器等超參數(shù)。除以上外,本項目中文版,使用了全詞mask(whole word mask)。在全詞Mask中,如果一個完整的詞的部分WordPiece子詞被mask,則同屬該詞的其他部分也會被mask,即全詞Mask。
本項目中并沒有直接實現(xiàn)dynamic mask。通過復(fù)制一個訓(xùn)練樣本得到多份數(shù)據(jù),每份數(shù)據(jù)使用不同mask,并加大復(fù)制的分?jǐn)?shù),可間接得到dynamic mask效果。
中文全詞遮蔽 Whole Word Mask
?模型加載(以Sentence Pair Matching即句子對任務(wù),LCQMC為例)
下載LCQMC數(shù)據(jù)集,包含訓(xùn)練、驗證和測試集,訓(xùn)練集包含24萬口語化描述的中文句子對,標(biāo)簽為1或0。1為句子語義相似,0為語義不相似。
tensorFlow版本:
1、復(fù)制本項目: git clone https://github.com/brightmart/roberta_zh2、進(jìn)到項目(roberta_zh)中。假設(shè)你將RoBERTa預(yù)訓(xùn)練模型下載并解壓到該改項目的roberta_zh_large目錄,即roberta_zh/roberta_zh_large運行命令:export BERT_BASE_DIR=./roberta_zh_large export MY_DATA_DIR=./data/lcqmc python run_classifier.py \--task_name=lcqmc_pair \--do_train=true \--do_eval=true \--data_dir=$MY_DATA_DIR \--vocab_file=$BERT_BASE_DIR/vocab.txt \--bert_config_file=$BERT_BASE_DIR/bert_config_large.json \--init_checkpoint=$BERT_BASE_DIR/roberta_zh_large_model.ckpt \--max_seq_length=128 \--train_batch_size=64 \--learning_rate=2e-5 \--num_train_epochs=3 \--output_dir=./checkpoint_lcqmc注:task_name為lcqmc_pair。這里已經(jīng)在run_classifier.py中的添加一個processor,并加到processors中,用于指定做lcqmc任務(wù),并加載訓(xùn)練和驗證數(shù)據(jù)。PyTorch加載方式,先參考issue 9;將很快提供更具體方式。
Learning Curve 學(xué)習(xí)曲線
If you have any question, you can raise an issue, or send me an email:?brightmart@hotmail.com
項目貢獻(xiàn)者,還包括:
skyhawk1990
本項目受到 TensorFlow Research Cloud (TFRC) 資助 / Project supported with Cloud TPUs from Google's TensorFlow Research Cloud (TFRC)
Reference
1、RoBERTa: A Robustly Optimized BERT Pretraining Approach
2、Pre-Training with Whole Word Masking for Chinese BERT
3、BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
4、LCQMC: A Large-scale Chinese Question Matching Corpus
?
現(xiàn)在,在「知乎」也能找到我們了
進(jìn)入知乎首頁搜索「PaperWeekly」
點擊「關(guān)注」訂閱我們的專欄吧
關(guān)于PaperWeekly
PaperWeekly 是一個推薦、解讀、討論、報道人工智能前沿論文成果的學(xué)術(shù)平臺。如果你研究或從事 AI 領(lǐng)域,歡迎在公眾號后臺點擊「交流群」,小助手將把你帶入 PaperWeekly 的交流群里。
▽ 點擊 |?閱讀原文?| 訪問項目主頁
總結(jié)
以上是生活随笔為你收集整理的RoBERTa中文预训练模型:RoBERTa for Chinese的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从局部脑到全脑:时空域分层神经网络脑电情
- 下一篇: Score Function Trick