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