macbert4mdcspell_v2训练微调总结
本文总结了macbert4mdcspell_v2模型的训练微调过程。在v1版本基础上,通过优化训练数据(新增60万无修改数据和中小学课本数据)和改进训练策略(7个epoch训练,最后不mask),使用1000万混合数据集进行训练。测评采用公开数据集,结果显示v2版本在多个指标上优于v1和其他对比模型(如macbert4csc-base-chinese和chinese-text-correction
·
macbert4mdcspell_v2训练微调总结
背景
GitHub项目:https://github.com/yongzhuo/macro-correct
初始训练的macbert4mdcspell_v1效果不错,但是在Macropodus/csc_eval_public数据集上的平均F1差一点没到70;
使用过程中发现macbert4mdcspell_v1容易过度纠错, 于是开始整理训练数据集,从新开始训练。
训练细节
训练数据
1000万,既有开源数据,也有基于yongzhuo/char-similar混淆词典构建的生成数据集;
新加入60万无修改数据; 新加入中小学课本数据;
训练参数:
"gradient_accumulation_steps": 4,
"num_warmup_steps": 128,
"max_train_steps": 468300,
"num_train_epochs": 7,
"train_batch_size": 32,
"eval_batch_size": 32,
"learning_rate": 3e-05,
"max_seq_length": 128,
"max_grad_norm": 1.0,
"weight_decay": 0.0005,
"save_steps": 1000,
"seed": 42,
"lr_scheduler_type": "cosine",
"loss_type": "focal_loss",
"mask_mode": "noerror",
"loss_det_rate": 0.15,
"mask_rate": 0.15,
"threshold": 0.5,
"flag_cuda": true,
"flag_skip": true,
"flag_mft": true,
"num_workers": 2,
训练策略
1、全部数据随机mask=0.15非标注数据;
2、数据集切分为多个块分别加载;
3、训练7个epoch;
4、最后一个epoch不mask;
训练日志


测评
说明
- 所有训练数据均来自公网或开源数据, 训练数据为1千万左右, 混淆词典较大;
- 所有测试数据均来自公网或开源数据, 测评数据地址为Macropodus/csc_eval_public;
- 测评代码主要为tcEval.py; 其中qwen25_1-5b_pycorrector的测评代码在目录eval
- 评估标准:过纠率(过度纠错, 即高质量正确句子的错误纠正); 句子级宽松标准的准确率/精确率/召回率/F1(同shibing624/pycorrector); 句子级严格标准的准确率/精确率/召回率/F1(同wangwang110/CSC); 字符级别的准确率/精确率/召回率/F1(错别字);
- qwen25_1-5b_pycorrector权重地址在shibing624/chinese-text-correction-1.5b
- macbert4csc_pycorrector权重地址在shibing624/macbert4csc-base-chinese;
- macbert4mdcspell_v1权重地址在Macropodus/macbert4mdcspell_v1;
- macbert4mdcspell_v2权重地址在Macropodus/macbert4mdcspell_v2;
- macbert4csc_v2权重地址在Macropodus/macbert4csc_v2;
- macbert4csc_v1权重地址在Macropodus/macbert4csc_v1;
- bert4csc_v1权重地址在Macropodus/bert4csc_v1;
3.1 测评数据
1.gen_de3.json(5545): '的地得'纠错, 由人民日报/学习强国/chinese-poetry等高质量数据人工生成;
2.lemon_v2.tet.json(1053): relm论文提出的数据, 多领域拼写纠错数据集(7个领域), ; 包括game(GAM), encyclopedia (ENC), contract (COT), medical care(MEC), car (CAR), novel (NOV), and news (NEW)等领域;
3.acc_rmrb.tet.json(4636): 来自NER-199801(人民日报高质量语料);
4.acc_xxqg.tet.json(5000): 来自学习强国网站的高质量语料;
5.gen_passage.tet.json(10000): 源数据为qwen生成的好词好句, 由几乎所有的开源数据汇总的混淆词典生成;
6.textproof.tet.json(1447): NLP竞赛数据, TextProofreadingCompetition;
7.gen_xxqg.tet.json(5000): 源数据为学习强国网站的高质量语料, 由几乎所有的开源数据汇总的混淆词典生成;
8.faspell.dev.json(1000): 视频字幕通过OCR后获取的数据集; 来自爱奇艺的论文faspell;
9.lomo_tet.json(5000): 主要为音似中文拼写纠错数据集; 来自腾讯; 人工标注的数据集CSCD-NS;
10.mcsc_tet.5000.json(5000): 医学拼写纠错; 来自腾讯医典APP的真实历史日志; 注意论文说该数据集只关注医学实体的纠错, 常用字等的纠错并不关注;
11.ecspell.dev.json(1500): 来自ECSpell论文, 包括(law/med/gov)等三个领域;
12.sighan2013.dev.json(1000): 来自sighan13会议;
13.sighan2014.dev.json(1062): 来自sighan14会议;
14.sighan2015.dev.json(1100): 来自sighan15会议;
3.2 测评再说明
1.数据预处理, 测评数据都经过 全角转半角,繁简转化,标点符号标准化等操作;
2.指标带common的极为宽松指标, 同开源项目pycorrector的评估指标;
3.指标带strict的极为严格指标, 同开源项目[wangwang110/CSC](https://github.com/wangwang110/CSC);
4.macbert4mdcspell_v1/v2模型为训练使用mdcspell架构+bert的mlm-loss, 但是推理的时候只用bert-mlm;
5.acc_rmrb/acc_xxqg数据集没有错误, 用于评估模型的误纠率(过度纠错);
6.qwen25_1-5b_pycorrector的模型为shibing624/chinese-text-correction-1.5b, 其训练数据包括了lemon_v2/mcsc_tet/ecspell的验证集和测试集, 其他的bert类模型的训练不包括验证集和测试集;
7.xxx_rethink1是指再多预测1次, xxx_thr30表示阈值为0.3;
3.3 测评结果
3.3.1 F1(common_cor_f1)
| model/common_cor_f1 | avg | gen_de3 | lemon_v2 | gen_passage | text_proof | gen_xxqg | faspell | lomo_tet | mcsc_tet | ecspell | sighan2013 | sighan2014 | sighan2015 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| shibing624/macbert4csc-base-chinese | 45.8 | 42.44 | 42.89 | 31.49 | 46.31 | 26.06 | 32.7 | 44.83 | 27.93 | 55.51 | 70.89 | 61.72 | 66.81 |
| shibing624/chinese-text-correction-1.5b | 45.11 | 27.29 | 89.48 | 14.61 | 83.9 | 13.84 | 18.2 | 36.71 | 96.29 | 88.2 | 36.41 | 15.64 | 20.73 |
| twnlp/ChineseErrorCorrector3-4B | 53.59 | 30.28 | 89.43 | 22.94 | 39.9 | 16.89 | 30.53 | 71.0 | 99.92 | 72.43 | 65.02 | 47.81 | 56.88 |
| relm_v1 | 54.12 | 89.86 | 51.79 | 38.4 | 63.74 | 30.6 | 31.95 | 49.82 | 64.7 | 73.57 | 66.4 | 39.87 | 48.8 |
| bert4csc_v1 | 62.28 | 93.73 | 61.99 | 44.79 | 68.0 | 35.03 | 48.28 | 61.8 | 64.41 | 79.11 | 77.66 | 51.01 | 61.54 |
| macbert4csc_v1 | 68.55 | 96.67 | 65.63 | 48.4 | 75.65 | 38.43 | 51.76 | 70.11 | 80.63 | 85.55 | 81.38 | 57.63 | 70.7 |
| macbert4csc_v2 | 68.6 | 96.74 | 66.02 | 48.26 | 75.78 | 38.84 | 51.91 | 70.17 | 80.71 | 85.61 | 80.97 | 58.22 | 69.95 |
| macbert4mdcspell_v1 | 71.1 | 96.42 | 70.06 | 52.55 | 79.61 | 43.37 | 53.85 | 70.9 | 82.38 | 87.46 | 84.2 | 61.08 | 71.32 |
| macbert4mdcspell_v2 | 71.23 | 96.42 | 65.8 | 52.35 | 75.94 | 43.5 | 53.82 | 72.66 | 82.28 | 88.69 | 82.51 | 65.59 | 75.26 |
| macbert4mdcspell_v1_rethink2 | 69.64 | 92.4 | 67.99 | 57.69 | 77.49 | 50.38 | 53.96 | 69.35 | 84.65 | 88.26 | 70.96 | 56.05 | 66.54 |
| macbert4mdcspell_v2_rethink2 | 72.54 | 95.59 | 65.54 | 58.01 | 75.86 | 49.67 | 55.56 | 72.78 | 84.65 | 90.78 | 80.93 | 65.74 | 75.39 |
3.3.2 acc(common_cor_acc)
| model/common_cor_acc | avg | gen_de3 | lemon_v2 | gen_passage | text_proof | gen_xxqg | faspell | lomo_tet | mcsc_tet | ecspell | sighan2013 | sighan2014 | sighan2015 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| shibing624/macbert4csc-base-chinese | 48.26 | 26.96 | 28.68 | 34.16 | 55.29 | 28.38 | 22.2 | 60.96 | 57.16 | 67.73 | 55.9 | 68.93 | 72.73 |
| shibing624/chinese-text-correction-1.5b | 46.09 | 15.82 | 81.29 | 22.96 | 82.17 | 19.04 | 12.8 | 50.2 | 96.4 | 89.13 | 22.8 | 27.87 | 32.55 |
| twnlp/ChineseErrorCorrector3-4B | 51.85 | 17.87 | 81.2 | 27.32 | 48.17 | 23.44 | 20.8 | 77.16 | 99.92 | 76.6 | 49.0 | 47.18 | 53.55 |
| relm_v1 | 51.9 | 81.71 | 36.18 | 37.04 | 63.99 | 29.34 | 22.9 | 51.98 | 74.1 | 76.0 | 50.3 | 45.76 | 53.45 |
| bert4csc_v1 | 60.76 | 88.21 | 45.96 | 43.13 | 68.97 | 35.0 | 34.0 | 65.86 | 73.26 | 81.8 | 64.5 | 61.11 | 67.27 |
| macbert4csc_v1 | 65.34 | 93.56 | 49.76 | 44.98 | 74.64 | 36.1 | 37.0 | 73.0 | 83.6 | 86.87 | 69.2 | 62.62 | 72.73 |
| macbert4csc_v2 | 65.22 | 93.69 | 50.14 | 44.92 | 74.64 | 36.26 | 37.0 | 72.72 | 83.66 | 86.93 | 68.5 | 62.43 | 71.73 |
| macbert4mdcspell_v1 | 67.15 | 93.09 | 54.8 | 47.71 | 78.09 | 39.52 | 38.8 | 71.92 | 84.78 | 88.27 | 73.2 | 63.28 | 72.36 |
| macbert4mdcspell_v2 | 68.31 | 93.09 | 50.05 | 48.72 | 75.74 | 40.52 | 38.9 | 76.9 | 84.8 | 89.73 | 71.0 | 71.94 | 78.36 |
| macbert4mdcspell_v1_rethink2 | 65.04 | 85.88 | 52.42 | 51.69 | 76.23 | 44.52 | 38.9 | 70.78 | 86.48 | 88.93 | 55.8 | 59.98 | 68.91 |
| macbert4mdcspell_v2_rethink2 | 69.14 | 91.56 | 49.76 | 53.01 | 75.67 | 44.84 | 40.5 | 76.98 | 86.56 | 91.47 | 68.8 | 72.03 | 78.45 |
3.3.3 acc(acc_true, thr=0.75, 测评过度修改)
| model/acc | avg | acc_rmrb | acc_xxqg |
|---|---|---|---|
| shibing624/macbert4csc-base-chinese | 99.24 | 99.22 | 99.26 |
| shibing624/chinese-text-correction-1.5b | 82.0 | 77.14 | 86.86 |
| twnlp/ChineseErrorCorrector3-4B | 77.03 | 76.96 | 77.1 |
| relm_v1 | 93.47 | 90.21 | 96.74 |
| bert4csc_v1 | 98.71 | 98.36 | 99.06 |
| macbert4csc_v1 | 97.72 | 96.72 | 98.72 |
| macbert4csc_v2 | 97.89 | 96.98 | 98.8 |
| macbert4mdcspell_v1 | 97.75 | 96.51 | 98.98 |
| macbert4mdcspell_v2 | 99.54 | 99.22 | 99.86 |
| macbert4mdcspell_v1_rethink2 | 92.78 | 88.31 | 97.24 |
| macbert4mdcspell_v2_rethink2 | 98.15 | 96.72 | 99.58 |
3.4 测评新数据集(alipayseq)
- alipayseq.tet.json: 阿里搜索真实数据, 论文:《Towards Better Chinese Spelling Check for Search Engines: A New Dataset and Strong Baseline》;
- WSDM-24的论文, macbert4xxx系列模型都没有训练过该数据集
3.4.1 F1(common_cor_f1)
| model/common_cor_f1 | alipayseq |
|---|---|
| shibing624/macbert4csc | 15.36 |
| twnlp/ChineseErrorCorrector3-4B | 42.84 |
| bert4csc_v1 | 42.23 |
| macbert4csc_v1 | 48.45 |
| macbert4csc_v2 | 45.60 |
| macbert4mdcspell_v1 | 48.97 |
| macbert4mdcspell_v2 | 50.41 |
3.4.2 acc(common_cor_acc)
| model/common_cor_acc | alipayseq |
|---|---|
| shibing624/macbert4csc | 13.74 |
| twnlp/ChineseErrorCorrector3-4B | 62.90 |
| bert4csc_v1 | 41.61 |
| macbert4csc_v1 | 48.51 |
| macbert4csc_v2 | 46.70 |
| macbert4mdcspell_v1 | 51.90 |
| macbert4mdcspell_v2 | 63.60 |
结论
1.macbert4csc_v1/macbert4csc_v2/macbert4mdcspell_v1等模型使用多种领域数据训练, 比较均衡, 也适合作为第一步的预训练模型, 可用于专有领域数据的继续微调;
2.MFT(Mask-Correct)依旧有效, 不过对于数据量足够的情形提升不明显, 可能也是误纠率升高的一个重要原因;
3.训练好的模型对"地得的"等高频错误具有较高的识别率和纠错率;
4.macbert4mdcspell_v2的MFT只70%的时间no-error-mask(0.15), 15%的时间target-to-target, 15%的时间不mask;
5.对于macbert4mdcspell, rethink能更好处理存在多个错误的句子(适合错误多的情况gen_passage/gen_xxqg这些错误数多的数据集都提升了4%, 多预测3次效果最佳, 考虑性能问题可以多预测1次), 同时rethink对过度纠错的影响不大;
6.对于macbert4mdcspell, thr阈值设置能更好地避免过度纠错, 除非是特别需要精确率的情况, 否则不建议超过0.5(0.5往后对效果的影响就比较大了);
7.shibing624/chinese-text-correction-1.5b和twnlp/ChineseErrorCorrector3-4B都用了部分数据集的测试集参与训练,比较明显的有mcsc_tet(快100%了, shibing624/chinese-text-correction-1.5b是明确说了有放测试集的, 可能是twnlp/ChineseErrorCorrector3-4B也用了同样的数据), 用了测试数据的可能还有lemon_v2/text_proof/lomo_tet/ecspell;
8.对于CSC任务, 大模型过拟合更加严重, 特别容易吧正确的句子修改润色(查看表3.3.3), decode-only模型不容易控制阈值;
9.macbert4mdcspell_v2使用了部分target-to-target无错误训练,误纠率明显提升;
10.相比macbert4mdcspell_v1,macbert4mdcspell_v2效果明显有所提升;
11.macbert4mdcspell_v2泛化能力不错,即便是没见过的alipayseq数据集,效果也不错; 但是文言文训练语料偏少,在文言文上效果不佳;
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)