新版本
我們發布了對LM預訓練/填充和F-Divergence的對抗訓練。
LMS的大規模對抗培訓:明礬代碼。
常識性推理的混合神經網絡模型:HNN代碼
如果要使用舊版本,請使用以下CMD克隆代碼:
git clone -b v0.1 https://github.com/namisan/mt-dnn.git
更新
我們很遺憾地通知您,由於政策的改變,它不再提供用於模型共享的公共存儲空間。我們正在努力尋找解決方案。
該Pytorch軟件包實現了多任務深度神經網絡(MT-DNN),以實現自然語言理解,如下所述
小劉*,Pengcheng He*,Weizhu Chen和Jianfeng Gao
多任務深度神經網絡,用於自然語言理解
ACL 2019
*:同等貢獻
小劉,彭本
通過知識蒸餾來改善多任務深度神經網絡,以了解自然語言理解
Arxiv版本
Liyuan Liu,Haoming Jiang,Pengcheng He,Weizhu Chen,Xiaodong Liu,Jianfeng Gao和Jiawei Han
關於自適應學習率及以後的差異
ICLR 2020
Haoming Jiang,Pengcheng HE,Weizhu Chen,Xiaodong Liu,Jianfeng Gao和Tuo Zhao
智能:通過原則正規化優化,預先訓練的自然語言模型的強大而有效的微調
ACL 2020
小劉,王,江吉,霍鄭,Xueyun Zhu,Emmanuel Awa,Pengcheng HE,Weizhu Chen,Hoifung Poon,Guihong Cao,Jianfeng Gao
多任務多任務深神經網絡的Microsoft工具包,用於自然語言理解
ACL 2020
Hao Cheng和Siaodong Liu和Lis Pereira和Yaoliang Yu和Jianfeng Gao
後差正規化和F差異以改善模型魯棒性
NAACL 2021
Python3.6
參考下載和安裝:https://www.python.org/downloads/release/python-360/
安裝要求> pip install -r requirements.txt
拉碼頭> docker pull allenlao/pytorch-mt-dnn:v1.3
運行Docker
> docker run -it --rm --runtime nvidia allenlao/pytorch-mt-dnn:v1.3 bash
如果您首先使用Docker:https://docs.docker.com/,請參閱以下鏈接。
下載數據> sh download.sh
請參閱下載粘合數據集:https://gluebenchmark.com/
預處理數據> sh experiments/glue/prepro.sh
訓練> python train.py
請注意,我們對基本MT-DNN模型進行了4個V100 GPU進行實驗。您可能需要減少其他GPU的批量尺寸。
MTL改進:使用所有膠水任務(不包括WNLI)學習新的共享表示形式,通過MTL通過MTL初始化的MT-DNN(共享層)(共享層)。
請注意,我們在8個V100 GPU(32G)上進行了該實驗,批量大小為32。
>scriptsrun_mt_dnn.sh Finetuning:針對每個膠水任務的Finetune MT-DNN,以獲取特定於任務的模型。
在這裡,我們提供了兩個示例STS-B和RTE。您可以使用類似的腳本來列出所有膠水任務。
> scriptsrun_stsb.sh> scriptsrun_rte.sh Scitail的域適應>scriptsscitail_domain_adaptation_bash.sh
SNLI的域適應>scriptssnli_domain_adaptation_bash.sh
預處理數據
a)將NER數據下載到數據/NER中,包括:{train/waled/test} .txt
b)將NER數據轉換為規範格式: > python experimentsnerprepro.py --data dataner --output_dir datacanonical_data
c)預處理典範數據到MT-DNN格式: > python prepro_std.py --root_dir datacanonical_data --task_def experimentsnerner_task_def.yml --model bert-base-uncased
訓練> python train.py --data_dir <data-path> --init_checkpoint <bert-base-uncased> --train_dataset squad,squad-v2 --test_dataset squad,squad-v2 --task_def experimentssquadsquad_task_def.yml
預處理數據
a)將小隊數據下載到數據/班級,包括:{train/strive} .txt,然後將文件名更改為:{squead_train/squead_dev} .json
b)將數據轉換為MT-DNN格式: > python experimentssquadsquad_prepro.py --root_dir datacanonical_data --task_def experimentssquadsquad_task_def.yml --model bert-base-uncased
訓練> python train.py --data_dir <data-path> --init_checkpoint <bert-model> --train_dataset ner --test_dataset ner --task_def experimentsnerner_task_def.yml
通過微調階段的ADV培訓: > python train.py --data_dir <data-path> --init_checkpoint <bert/mt-dnn-model> --train_dataset mnli --test_dataset mnli_matched,mnli_mismatched --task_def experimentsglueglue_task_def.yml --adv_train --adv_opt 1
提取一對文本示例的嵌入>python extractor.py --do_lower_case --finput input_examplespair-input.txt --foutput input_examplespair-output.json --bert_model bert-base-uncased --checkpoint mt_dnn_modelsmt_dnn_base.pt
請注意,這對文本由特殊令牌|||分開。您可以將input_examplespair-output.json引用為例如。
提取單句示例的嵌入>python extractor.py --do_lower_case --finput input_examplessingle-input.txt --foutput input_examplessingle-output.json --bert_model bert-base-uncased --checkpoint mt_dnn_modelsmt_dnn_base.pt
梯度積累
如果您的GPU很小,則可能需要使用梯度積累來使訓練穩定。
例如,如果您使用標誌: --grad_accumulation_step 4在培訓期間,則實際批量大小為batch_size * 4 。
FP16當前版本的MT-DNN還支持FP16培訓,請安裝APEX。
您只需要在培訓期間打開旗幟: --fp16
請參閱腳本: scriptsrun_mt_dnn_gc_fp16.sh
在這裡,我們介紹瞭如何將中國張量的BERT模型轉換為MT-DNN格式。
從Google Bert Web下載Bert模型:https://github.com/google-research/bert
運行MT-DNN格式的以下腳本python scriptsconvert_tf_to_pt.py --tf_checkpoint_root chinese_L-12_H-768_A-12 --pytorch_checkpoint_path chinese_L-12_H-768_A-12bert_base_chinese.pt
是的,我們通過MTL發布了預處理的共享嵌入,該嵌入與Bert Base/大型型號保持一致: mt_dnn_base.pt和mt_dnn_large.pt 。
獲得類似的模型:
>sh scriptsrun_mt_dnn.sh ,然後根據MNLI/RTE的平均DEV預性選擇最佳檢查點。scritpsstrip_model.py剝離特定於任務的層。對於Scitail/SNLI任務,目的是測試學習嵌入的概括,以及將其適應新域而不是複雜的模型結構,以與BERT進行直接比較。因此,我們對所有域自適應設置都使用線性投影。
區別在QNLI數據集中。請訪問膠水官方主頁以獲取更多詳細信息。如果您想將QNLI作為我們的論文進行配對排名任務,請確保使用舊的QNLI數據。
然後用標誌運行Prepro腳本: > sh experiments/glue/prepro.sh --old_glue
如果您有訪問舊版本數據的問題,請聯繫膠水團隊。
我們可以使用多任務改進模型來運行預測並產生合理的結果。但是要取得更好的結果,它需要對每個任務進行微調。在Arxiv中註意到紙張的紙是一個舊的膠水數據集。我們將如下提到的更新論文。
Bert Pytorch來自:https://github.com/huggingface/pytorch-preterained-bert
伯特:https://github.com/google-research/bert
我們還使用了一些代碼:https://github.com/kevinduh/san_mrc
@inproceedings{liu2019mt-dnn,
title = "Multi-Task Deep Neural Networks for Natural Language Understanding",
author = "Liu, Xiaodong and He, Pengcheng and Chen, Weizhu and Gao, Jianfeng",
booktitle = "Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/P19-1441",
pages = "4487--4496"
}
@article{liu2019mt-dnn-kd,
title={Improving Multi-Task Deep Neural Networks via Knowledge Distillation for Natural Language Understanding},
author={Liu, Xiaodong and He, Pengcheng and Chen, Weizhu and Gao, Jianfeng},
journal={arXiv preprint arXiv:1904.09482},
year={2019}
}
@inproceedings{liu2019radam,
title={On the Variance of the Adaptive Learning Rate and Beyond},
author={Liu, Liyuan and Jiang, Haoming and He, Pengcheng and Chen, Weizhu and Liu, Xiaodong and Gao, Jianfeng and Han, Jiawei},
booktitle={International Conference on Learning Representations},
year={2020}
}
@inproceedings{jiang2019smart,
title={SMART: Robust and Efficient Fine-Tuning for Pre-trained Natural Language Models through Principled Regularized Optimization},
author={Jiang, Haoming and He, Pengcheng and Chen, Weizhu and Liu, Xiaodong and Gao, Jianfeng and Zhao, Tuo},
booktitle = "Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics",
year={2020}
}
@article{liu2020mtmtdnn,
title={The Microsoft Toolkit of Multi-Task Deep Neural Networks for Natural Language Understanding},
author={Liu, Xiaodong and Wang, Yu and Ji, Jianshu and Cheng, Hao and Zhu, Xueyun and Awa, Emmanuel and He, Pengcheng and Chen, Weizhu and Poon, Hoifung and Cao, Guihong and Jianfeng Gao},
journal={arXiv preprint arXiv:2002.07972},
year={2020}
}
@inproceedings{liu2020mtmtdnn,
title = "The {M}icrosoft Toolkit of Multi-Task Deep Neural Networks for Natural Language Understanding",
author={Liu, Xiaodong and Wang, Yu and Ji, Jianshu and Cheng, Hao and Zhu, Xueyun and Awa, Emmanuel and He, Pengcheng and Chen, Weizhu and Poon, Hoifung and Cao, Guihong and Jianfeng Gao},
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2020.acl-demos.16",
year = "2020"
}
@article{cheng2020posterior,
title={Posterior Differential Regularization with f-divergence for Improving Model Robustness},
author={Cheng, Hao and Liu, Xiaodong and Pereira, Lis and Yu, Yaoliang and Gao, Jianfeng},
booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
year = "2021",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2021.naacl-main.85",
doi = "10.18653/v1/2021.naacl-main.85",
}
有關使用MT-DNN的幫助或問題,請提交GitHub問題。
有關與此軟件包有關的個人溝通,請聯繫Xiaodong Liu( [email protected] ),Yu Wang( [email protected] ),Pengcheng He( [email protected] ),Weizhu Chen [email protected] [email protected] [email protected] )或jianfeng gao( [email protected] )。