"Distilling task-specific knowledge from bert into simple neural networks"论文的实现
Distilled BiLSTM的教师模型采用微调过的BERT,学生模型采用简单神经网络LSTM。
蒸馏的目标是KD loss,即仅使用软标签进行蒸馏,将BERT中的知识蒸馏到LSTM中。
完整的环境可以通过以下命令安装:
conda create -n tinybert python=3.6
python3 -m pip install --find-links https://oneflow-inc.github.io/nightly oneflow_cu101 --user
注:以下操作时,根目录为
model_compress/distil
如何获取数据请查阅这里
如何微调教师模型请查阅这里
执行以下脚本将教师模型蒸馏到学生模型:
最大序列长度为32,词表大小为10000
bash run_train_student_distilled_lstm.sh
蒸馏过的学生模型下载链接如下(SST-2数据集):
下载链接: https://pan.baidu.com/s/1M4XzB2DnLikglxVFvhnYpw 提取码: hqhj
执行以下脚本进行测试:
bash run_eval_student_distilled_lstm.sh
在SST-2 DEV数据集上: