BERT of Theseus
1.0.0
紙的代碼“這些伯特:通過漸進模塊更換來壓縮伯特”。
這些伯特(Bert)是一種新的壓縮伯特(Bert),它逐漸替換了原始伯特的組件。

如果您在研究中使用此代碼,請引用我們的論文:
@inproceedings { xu-etal-2020-bert ,
title = " {BERT}-of-Theseus: Compressing {BERT} by Progressive Module Replacing " ,
author = " Xu, Canwen and
Zhou, Wangchunshu and
Ge, Tao and
Wei, Furu and
Zhou, Ming " ,
booktitle = " Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP) " ,
month = nov,
year = " 2020 " ,
address = " Online " ,
publisher = " Association for Computational Linguistics " ,
url = " https://www.aclweb.org/anthology/2020.emnlp-main.633 " ,
pages = " 7859--7869 "
}新:我們上傳了一個腳本,用於對膠水任務進行預測並準備排行榜提交。在這裡查看!
我們的代碼建立在擁抱面/變壓器上。要使用我們的代碼,您必須克隆並安裝擁抱面/變壓器。
# For compression with a replacement scheduler
export GLUE_DIR=/path/to/glue_data
export TASK_NAME=MRPC
python ./run_glue.py
--model_name_or_path /path/to/saved_predecessor
--task_name $TASK_NAME
--do_train
--do_eval
--do_lower_case
--data_dir " $GLUE_DIR / $TASK_NAME "
--max_seq_length 128
--per_gpu_train_batch_size 32
--per_gpu_eval_batch_size 32
--learning_rate 2e-5
--save_steps 50
--num_train_epochs 15
--output_dir /path/to/save_successor/
--evaluate_during_training
--replacing_rate 0.3
--scheduler_type linear
--scheduler_linear_k 0.0006 # For compression with a constant replacing rate
export GLUE_DIR=/path/to/glue_data
export TASK_NAME=MRPC
python ./run_glue.py
--model_name_or_path /path/to/saved_predecessor
--task_name $TASK_NAME
--do_train
--do_eval
--do_lower_case
--data_dir " $GLUE_DIR / $TASK_NAME "
--max_seq_length 128
--per_gpu_train_batch_size 32
--per_gpu_eval_batch_size 32
--learning_rate 2e-5
--save_steps 50
--num_train_epochs 15
--output_dir /path/to/save_successor/
--evaluate_during_training
--replacing_rate 0.5
--steps_for_replacing 2500 有關參數的詳細說明,請參閱源代碼。
我們在MNLI上提供了一個6層預審預週化的模型作為通用模型,該模型可以轉移到其他句子分類任務上,在六個膠水任務(DEV SET)上超過了(具有相同的6層結構)的句子分類任務(具有相同的6層結構)。
| 方法 | mnli | MRPC | Qnli | QQP | rte | SST-2 | STS-B |
|---|---|---|---|---|---|---|---|
| 伯特基 | 83.5 | 89.5 | 91.2 | 89.8 | 71.1 | 91.5 | 88.9 |
| 蒸餾廠 | 79.0 | 87.5 | 85.3 | 84.9 | 59.9 | 90.7 | 81.2 |
| 這些伯特 | 82.1 | 87.5 | 88.8 | 88.8 | 70.1 | 91.8 | 87.8 |
您可以使用擁抱面/變壓器輕鬆加載我們的通用模型。
from transformers import AutoTokenizer , AutoModel
tokenizer = AutoTokenizer . from_pretrained ( "canwenxu/BERT-of-Theseus-MNLI" )
model = AutoModel . from_pretrained ( "canwenxu/BERT-of-Theseus-MNLI" )如果您想貢獻並添加更多任務(目前只有膠水),請提交拉動請求並與我聯繫。另外,如果您發現任何問題或錯誤,請報告問題。謝謝!
我們在此處列出了社區的一些第三方實施。請將您的實現添加到此列表中:
Tensorflow Implementation (tested on NER) :https://github.com/qiufengyuyi/bert-oft------theseus-tfKeras Implementation (tested on text classification) :https://github.com/bojone/bert-of-theseus