新版本
我们发布了对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] )。