(升级)模型蒸馏-分类任务
更新时间:2022-08-03
代码结构
任务代码位于:./wenxin_appzoo/tasks/model_distillation_cls
.
├── data
│ ├── download_general_data.sh
│ ├── download_task_data.sh
│ ├── predict_demo
│ ├── wiki_wenxin
│ └── iflytek
├── examples
│ ├── iflytek
├── inference
│ ├── custom_inference.py
├── model
│ ├── base_cls.py
│ ├── ernie_classification.py
│ ├── general_enhanced_distill_minilm.py
│ ├── task_distill_minilm.py
├── reader
│ ├── cls_field_reader.py
│ ├── ernie_classification_dataset_reader.py
├── run_infer.py
├── run_trainer.py
└── trainer
├── custom_dynamic_trainer.py
开始使用
数据准备
使用iflytek作为任务数据集,中文wiki百科作为通用数据集。
- 下载方式
cd ./wenxin_appzoo/tasks/model_distillation_cls/data
bash download_task_data.sh
bash download_general_data.sh
```
### 分阶段运行
1. 准备预训练教师模型和学生模型
```shell
cd wenxin_appzoo/models_hub
bash download_ernie_3.0_large_distill_ch.sh
bash download_ernie_3.0_tiny_ch.sh
cd wenxin_appzoo/tasks/model_distillation_cls
```
2. fine-tune 教师模型
```shell
python run_trainer.py --param_path ./examples/iflytek/ernie_3.0_large_ft.json
```
3. 任务蒸馏通用数据增强阶段:GED
- 首先需要根据评估指标选择最优的fine-tuned教师模型,然后运行:
```shell
python run_trainer.py --param_path ./examples/iflytek/minilm_ged.json
```
4. 任务蒸馏二阶段:TD1
```shell
python run_trainer.py --param_path ./examples/iflytek/minilm_td1.json
```
5. 任务蒸馏二阶段:TD2
```shell
python run_trainer.py --param_path ./examples/iflytek/minilm_td2.json
-
对学生模型的效果进行预测
python run_infer.py --param_path ./examples/iflytek/minilm_student_infer.json