新しいリリース
LM Pre-Training/FinetuningとF-Divergenceの両方の敵対的なトレーニングをリリースしました。
LMSの大規模な敵対的トレーニング:ミョウバンコード。
相性的推論のためのハイブリッドニューラルネットワークモデル:HNNコード
古いバージョンを使用する場合は、次のCMDを使用してコードをクローンしてください。
git clone -b v0.1 https://github.com/namisan/mt-dnn.git
アップデート
ポリシーが変更されたため、モデル共有のためのパブリックストレージを提供しなくなったことをお知らせすることを後悔しています。私たちは解決策を見つけるために一生懸命働いています。
このPytorchパッケージは、自然言語の理解のためにマルチタスクディープニューラルネットワーク(MT-DNN)を実装しています。
Xiaodong liu*、Pengcheng He*、Weizhu Chen、Jianfeng Gao
自然言語理解のためのマルチタスクディープニューラルネットワーク
ACL 2019
*:平等な貢献
Xiaodong Liu、Pengcheng He、Weizhu Chen、Jianfeng Gao
自然言語理解のための知識蒸留によるマルチタスクの深いニューラルネットワークの改善
arxivバージョン
Liyuan Liu、Haoming Jiang、Pengcheng He、Weizhu Chen、Xiaodong Liu、Jianfeng Gao、Jiawei Han
適応学習率とそれ以降の分散について
ICLR 2020
ハーミン・ジアン、ペンチェン・彼、ワイズフ・チェン、Xiaodong Liu、Jianfeng Gao、Tuo Zhao
スマート:原則的な正規化された最適化を通じて、事前に訓練された自然言語モデルの堅牢で効率的な微調整
ACL 2020
Xiaodong Liu、Yu Wang、Jianshu Ji、Hao Cheng、Xueyun Zhu、Emmanuel Awa、Pengcheng He、Weizhu Chen、Hoifung Poon、Guihong Cao、Jianfeng Gao
自然言語理解のためのマルチタスクディープニューラルネットワークのマイクロソフトツールキット
ACL 2020
Hao ChengとXiaodong 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を引っ張ります> 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洗練:MT-DNN(共有レイヤー)を洗練し、事前に訓練されたBERTモデルで初期化され、WNLIを除くすべての接着剤タスクを使用して新しい共有表現を学習します。
この実験は、バッチサイズが32の8 V100 GPU(32G)で実行されたことに注意してください。
>scriptsrun_mt_dnn.sh Finetuning:各接着剤タスクにFinetune MT-DNNがタスク固有のモデルを取得します。
ここでは、STS-BとRTEの2つの例を提供します。同様のスクリプトを使用して、すべての接着剤タスクを獲得できます。
> scriptsrun_stsb.sh> scriptsrun_rte.sh Scitailのドメイン適応>scriptsscitail_domain_adaptation_bash.sh
SNLIのドメイン適応>scriptssnli_domain_adaptation_bash.sh
プリプロースデータ
a){train/valid/test} .txtを含むデータ/nerにnerデータをダウンロードします
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/valid} .txtを含む分隊データをデータ/分隊にダウンロードしてから、ファイル名を次のように変更します。{squad_train/squad_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を参照してください
ここでは、中国のTensorflow 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/大規模モデルに整列したMTLを介して、 mt_dnn_base.ptおよびmt_dnn_large.ptに整列した、MTLを介して前処理された共有埋め込みをリリースしました。
同様のモデルを取得するには:
>sh scriptsrun_mt_dnn.shを実行し、mnli/rteの平均的な開発の事前形成に基づいて最適なチェックポイントを選択します。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-pretreandebertからです
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] )、jianshu ji( [email protected] )に連絡してください。 [email protected] )またはjianfeng gao( [email protected] )。