Macropodus/macbert4mdcspell_v3

Model

1

stars

4

commits

12

linked in READMEs

Jan 29, 2026

updated

bert
chinese-spelling-check
chinses-spelling-correct
csc
macro-correct
mdcspell
pytorch
tensorboard
text-correct
text-generation
中文拼写纠错
文本纠错
Browse cluster: Chinese Spelling Error Correction

README

macbert4mdcspell

概述(macbert4mdcspell)

  • macro-correct, 中文拼写纠错CSC测评(文本纠错), 权重使用
  • 项目地址在 https://github.com/yongzhuo/macro-correct
  • 本模型权重为macbert4mdcspell_v3, 使用mdcspell架构, 其特点是det_label和cor_label交互;
  • 训练时加入了macbert的mlm-loss, 推理时舍弃了macbert后面的部分;
  • 如何使用: 1.使用transformers调用; 2.使用macro-correct项目调用; 详情见三、调用(Usage);
  • 为了修复过纠问题, macbert4mdcspell_v3的MFT只85%的时间no-error-mask(0.15), 5%的时间target-to-target, 10%的时间不mask;
  • 训练数据为 2000w+, 相对于macbert4mdcspell_v2, 强化了古诗和文言文的训练;

目录

一、测评(Test)

1.1 测评数据来源

地址为Macropodus/csc_eval_public, 所有训练数据均来自公网或开源数据, 训练数据为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会议;
15.wenyanwen_and_poetry.tet.json(5000), 来自课本古诗和通用文言文;

1.2 测评数据预处理

测评数据都经过 全角转半角,繁简转化,标点符号标准化等操作;

1.3 其他说明

1.指标带common的极为宽松指标, 同开源项目pycorrector的评估指标;
2.指标带strict的极为严格指标, 同开源项目[wangwang110/CSC](https://github.com/wangwang110/CSC);
3.macbert4mdcspell_v1/v2/v3模型为训练使用mdcspell架构+bert的mlm-loss, 但是推理的时候只用bert-mlm;
4.acc_rmrb/acc_xxqg数据集没有错误, 用于评估模型的误纠率(过度纠错);
5.qwen25_1-5b_pycorrector的模型为shibing624/chinese-text-correction-1.5b, 其训练数据包括了lemon_v2/mcsc_tet/ecspell的验证集和测试集, 其他的bert类模型的训练不包括验证集和测试集;

二、重要指标

2.1 F1(common_cor_f1)

model/common_cor_f1avggen_de3lemon_v2gen_passagetext_proofgen_xxqgfaspelllomo_tetmcsc_tetecspellsighan2013sighan2014sighan2015
shibing624/macbert4csc-base-chinese45.842.4442.8931.4946.3126.0632.744.8327.9355.5170.8961.7266.81
shibing624/chinese-text-correction-1.5b45.1127.2989.4814.6183.913.8418.236.7196.2988.236.4115.6420.73
twnlp/ChineseErrorCorrector3-4B53.5930.2889.4322.9439.916.8930.5371.099.9272.4365.0247.8156.88
relm_v154.1289.8651.7938.463.7430.631.9549.8264.773.5766.439.8748.8
bert4csc_v162.2893.7361.9944.7968.035.0348.2861.864.4179.1177.6651.0161.54
macbert4csc_v168.5596.6765.6348.475.6538.4351.7670.1180.6385.5581.3857.6370.7
macbert4csc_v268.696.7466.0248.2675.7838.8451.9170.1780.7185.6180.9758.2269.95
macbert4mdcspell_v171.196.4270.0652.5579.6143.3753.8570.982.3887.4684.261.0871.32
macbert4mdcspell_v271.2396.4265.852.3575.9443.553.8272.6682.2888.6982.5165.5975.26
macbert4mdcspell_v371.7196.4368.0759.3678.8150.0748.6774.5179.0387.1681.3164.2972.76
macbert4mdcspell_v1_rethink269.6492.467.9957.6977.4950.3853.9669.3584.6588.2670.9656.0566.54
macbert4mdcspell_v2_rethink272.5495.5965.5458.0175.8649.6755.5672.7884.6590.7880.9365.7475.39
macbert4mdcspell_v3_rethink271.8295.0567.4862.1978.055.249.574.2681.7287.5676.7562.9671.12

2.2 acc(common_cor_acc)

model/common_cor_accavggen_de3lemon_v2gen_passagetext_proofgen_xxqgfaspelllomo_tetmcsc_tetecspellsighan2013sighan2014sighan2015
shibing624/macbert4csc-base-chinese48.2626.9628.6834.1655.2928.3822.260.9657.1667.7355.968.9372.73
shibing624/chinese-text-correction-1.5b46.0915.8281.2922.9682.1719.0412.850.296.489.1322.827.8732.55
twnlp/ChineseErrorCorrector3-4B51.8517.8781.227.3248.1723.4420.877.1699.9276.649.047.1853.55
relm_v151.981.7136.1837.0463.9929.3422.951.9874.176.050.345.7653.45
bert4csc_v160.7688.2145.9643.1368.9735.034.065.8673.2681.864.561.1167.27
macbert4csc_v165.3493.5649.7644.9874.6436.137.073.083.686.8769.262.6272.73
macbert4csc_v265.2293.6950.1444.9274.6436.2637.072.7283.6686.9368.562.4371.73
macbert4mdcspell_v167.1593.0954.847.7178.0939.5238.871.9284.7888.2773.263.2872.36
macbert4mdcspell_v268.3193.0950.0548.7275.7440.5238.976.984.889.7371.071.9478.36
macbert4mdcspell_v368.0993.1152.4253.9177.8945.2834.276.8282.588.1369.268.8374.82
macbert4mdcspell_v1_rethink265.0485.8852.4251.6976.2344.5238.970.7886.4888.9355.859.9868.91
macbert4mdcspell_v2_rethink269.1491.5649.7653.0175.6744.8440.576.9886.5691.4768.872.0378.45
macbert4mdcspell_v3_rethink267.8490.5751.7656.2477.1949.1634.976.6484.488.4763.167.9873.64

2.3 acc(acc_true, thr=0.75)

model/accavgacc_rmrbacc_xxqg
shibing624/macbert4csc-base-chinese99.2499.2299.26
shibing624/chinese-text-correction-1.5b82.077.1486.86
twnlp/ChineseErrorCorrector3-4B77.0376.9677.1
relm_v193.4790.2196.74
bert4csc_v198.7198.3699.06
macbert4csc_v197.7296.7298.72
macbert4csc_v297.8996.9898.8
macbert4mdcspell_v197.7596.5198.98
macbert4mdcspell_v299.5499.2299.86
macbert4mdcspell_v398.8598.3299.38
macbert4mdcspell_v1_rethink292.7888.3197.24
macbert4mdcspell_v2_rethink298.1596.7299.58
macbert4mdcspell_v3_rethink298.8598.3299.38

数据集_alipayseq

model/common_cor_f1alipayseq
shibing624/macbert4csc15.36
twnlp/ChineseErrorCorrector3-4B42.84
bert4csc_v142.23
macbert4csc_v148.45
macbert4csc_v245.60
macbert4mdcspell_v148.97
macbert4mdcspell_v250.41
macbert4mdcspell_v350.14

数据集_古诗-文言文数据集测评

model/common_cor_f1detcor
shibing624/macbert4csc-base-chinese44.127.48
macbert4mdcspell_v158.9812.43
macbert4mdcspell_v250.6110.40
macbert4mdcspell_v373.2447.41

二、结论(Conclusion)

1.macbert4csc_v1/macbert4csc_v2/macbert4mdcspell_v1等模型使用多种领域数据训练, 比较均衡, 也适合作为第一步的预训练模型, 可用于专有领域数据的继续微调;
2.比较macbert4csc_pycorrector/bertbase4csc_v1/macbert4csc_v2/macbert4mdcspell_v1, 观察表2.3, 可以发现训练数据越多, 准确率提升的同时, 误纠率也会稍微高一些;
3.MFT(Mask-Correct)依旧有效, 不过对于数据量足够的情形提升不明显, 可能也是误纠率升高的一个重要原因;
4.训练数据中也存在文言文数据, 训练好的模型也支持文言文纠错;
5.训练好的模型对"地得的"等高频错误具有较高的识别率和纠错率;
6.macbert4mdcspell_v2的MFT只70%的时间no-error-mask(0.15), 15%的时间target-to-target, 15%的时间不mask;
7.macbert4mdcspell_v3的MFT只85%的时间no-error-mask(0.15), 5%的时间target-to-target, 10%的时间不mask;(强化古文/现代文, 但降target-to-target比例太多使其比v2过纠多一点点)

三、调用(Usage)

3.1 使用macro-correct

import os
os.environ["MACRO_CORRECT_FLAG_CSC_TOKEN"] = "1"
from macro_correct import correct
### 默认纠错(list输入)
text_list = ["真麻烦你了。希望你们好好的跳无",
             "少先队员因该为老人让坐",
             "机七学习是人工智能领遇最能体现智能的一个分知",
             "一只小鱼船浮在平净的河面上"
             ]
text_csc = correct(text_list)
print("默认纠错(list输入):")
for res_i in text_csc:
    print(res_i)
print("#" * 128)

"""
默认纠错(list输入):
{'index': 0, 'source': '真麻烦你了。希望你们好好的跳无', 'target': '真麻烦你了。希望你们好好地跳舞', 'errors': [['的', '地', 12, 0.6584], ['无', '舞', 14, 1.0]]}
{'index': 1, 'source': '少先队员因该为老人让坐', 'target': '少先队员应该为老人让坐', 'errors': [['因', '应', 4, 0.995]]}
{'index': 2, 'source': '机七学习是人工智能领遇最能体现智能的一个分知', 'target': '机器学习是人工智能领域最能体现智能的一个分支', 'errors': [['七', '器', 1, 0.9998], ['遇', '域', 10, 0.9999], ['知', '支', 21, 1.0]]}
{'index': 3, 'source': '一只小鱼船浮在平净的河面上', 'target': '一只小鱼船浮在平静的河面上', 'errors': [['净', '静', 8, 0.9961]]}
"""

3.2 使用 transformers

# !/usr/bin/python
# -*- coding: utf-8 -*-
# @time    : 2021/2/29 21:41
# @author  : Mo
# @function: transformers直接加载bert类模型测试


import traceback
import time
import sys
import os
os.environ["USE_TORCH"] = "1"
from transformers import BertConfig, BertTokenizer, BertForMaskedLM
import torch

# pretrained_model_name_or_path = "shibing624/macbert4csc-base-chinese"
pretrained_model_name_or_path = "Macropodus/macbert4mdcspell_v3"
# pretrained_model_name_or_path = "Macropodus/macbert4mdcspell_v2"
# pretrained_model_name_or_path = "Macropodus/macbert4mdcspell_v1"
# pretrained_model_name_or_path = "Macropodus/macbert4csc_v1"
# pretrained_model_name_or_path = "Macropodus/macbert4csc_v2"
# pretrained_model_name_or_path = "Macropodus/bert4csc_v1"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
max_len = 128

print("load model, please wait a few minute!")
tokenizer = BertTokenizer.from_pretrained(pretrained_model_name_or_path)
bert_config = BertConfig.from_pretrained(pretrained_model_name_or_path)
model = BertForMaskedLM.from_pretrained(pretrained_model_name_or_path)
model.to(device)
print("load model success!")

texts = [
    "机七学习是人工智能领遇最能体现智能的一个分知",
    "我是练习时长两念半的鸽仁练习生蔡徐坤",
    "真麻烦你了。希望你们好好的跳无",
    "他法语说的很好,的语也不错",
    "遇到一位很棒的奴生跟我疗天",
    "我们为这个目标努力不解",
]
len_mid = min(max_len, max([len(t)+2 for t in texts]))

with torch.no_grad():
    outputs = model(**tokenizer(texts, padding=True, max_length=len_mid,
                                return_tensors="pt").to(device))

def get_errors(source, target):
    """   极简方法获取 errors   """
    len_min = min(len(source), len(target))
    errors = []
    for idx in range(len_min):
        if source[idx] != target[idx]:
            errors.append([source[idx], target[idx], idx])
    return errors

result = []
for probs, source in zip(outputs.logits, texts):
    ids = torch.argmax(probs, dim=-1)
    tokens_space = tokenizer.decode(ids[1:-1], skip_special_tokens=False)
    text_new = tokens_space.replace(" ", "")
    target = text_new[:len(source)]
    errors = get_errors(source, target)
    print(source, " => ", target, errors)
    result.append([target, errors])
print(result)
"""
机七学习是人工智能领遇最能体现智能的一个分知  =>  机器学习是人工智能领域最能体现智能的一个分支 [['七', '器', 1], ['遇', '域', 10], ['知', '支', 21]]
我是练习时长两念半的鸽仁练习生蔡徐坤  =>  我是练习时长两年半的个人练习生蔡徐坤 [['念', '年', 7], ['鸽', '个', 10], ['仁', '人', 11]]
真麻烦你了。希望你们好好的跳无  =>  真麻烦你了。希望你们好好地跳舞 [['的', '地', 12], ['无', '舞', 14]]
他法语说的很好,的语也不错  =>  他法语说得很好,德语也不错 [['的', '得', 4], ['的', '德', 8]]
遇到一位很棒的奴生跟我疗天  =>  遇到一位很棒的女生跟我聊天 [['奴', '女', 7], ['疗', '聊', 11]]
我们为这个目标努力不解  =>  我们为这个目标努力不懈 [['解', '懈', 10]]
"""

四、论文(Paper)

五、参考(Refer)

六、引用(Cite)

For citing this work, you can refer to the present GitHub project. For example, with BibTeX:

@software{macro-correct,
    url = {https://github.com/yongzhuo/macro-correct},
    author = {Yongzhuo Mo},
    title = {macro-correct},
    year = {2025}

Contributors

Macropodus

4 commits

Macropodus/macbert4mdcspell_v3

Model

1

stars

4

commits

12

linked in READMEs

Jan 29, 2026

updated

bert
chinese-spelling-check
chinses-spelling-correct
csc
macro-correct
mdcspell
pytorch
tensorboard
text-correct
text-generation
中文拼写纠错
文本纠错
Browse cluster: Chinese Spelling Error Correction

README

macbert4mdcspell

概述(macbert4mdcspell)

  • macro-correct, 中文拼写纠错CSC测评(文本纠错), 权重使用
  • 项目地址在 https://github.com/yongzhuo/macro-correct
  • 本模型权重为macbert4mdcspell_v3, 使用mdcspell架构, 其特点是det_label和cor_label交互;
  • 训练时加入了macbert的mlm-loss, 推理时舍弃了macbert后面的部分;
  • 如何使用: 1.使用transformers调用; 2.使用macro-correct项目调用; 详情见三、调用(Usage);
  • 为了修复过纠问题, macbert4mdcspell_v3的MFT只85%的时间no-error-mask(0.15), 5%的时间target-to-target, 10%的时间不mask;
  • 训练数据为 2000w+, 相对于macbert4mdcspell_v2, 强化了古诗和文言文的训练;

目录

一、测评(Test)

1.1 测评数据来源

地址为Macropodus/csc_eval_public, 所有训练数据均来自公网或开源数据, 训练数据为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会议;
15.wenyanwen_and_poetry.tet.json(5000), 来自课本古诗和通用文言文;

1.2 测评数据预处理

测评数据都经过 全角转半角,繁简转化,标点符号标准化等操作;

1.3 其他说明

1.指标带common的极为宽松指标, 同开源项目pycorrector的评估指标;
2.指标带strict的极为严格指标, 同开源项目[wangwang110/CSC](https://github.com/wangwang110/CSC);
3.macbert4mdcspell_v1/v2/v3模型为训练使用mdcspell架构+bert的mlm-loss, 但是推理的时候只用bert-mlm;
4.acc_rmrb/acc_xxqg数据集没有错误, 用于评估模型的误纠率(过度纠错);
5.qwen25_1-5b_pycorrector的模型为shibing624/chinese-text-correction-1.5b, 其训练数据包括了lemon_v2/mcsc_tet/ecspell的验证集和测试集, 其他的bert类模型的训练不包括验证集和测试集;

二、重要指标

2.1 F1(common_cor_f1)

model/common_cor_f1avggen_de3lemon_v2gen_passagetext_proofgen_xxqgfaspelllomo_tetmcsc_tetecspellsighan2013sighan2014sighan2015
shibing624/macbert4csc-base-chinese45.842.4442.8931.4946.3126.0632.744.8327.9355.5170.8961.7266.81
shibing624/chinese-text-correction-1.5b45.1127.2989.4814.6183.913.8418.236.7196.2988.236.4115.6420.73
twnlp/ChineseErrorCorrector3-4B53.5930.2889.4322.9439.916.8930.5371.099.9272.4365.0247.8156.88
relm_v154.1289.8651.7938.463.7430.631.9549.8264.773.5766.439.8748.8
bert4csc_v162.2893.7361.9944.7968.035.0348.2861.864.4179.1177.6651.0161.54
macbert4csc_v168.5596.6765.6348.475.6538.4351.7670.1180.6385.5581.3857.6370.7
macbert4csc_v268.696.7466.0248.2675.7838.8451.9170.1780.7185.6180.9758.2269.95
macbert4mdcspell_v171.196.4270.0652.5579.6143.3753.8570.982.3887.4684.261.0871.32
macbert4mdcspell_v271.2396.4265.852.3575.9443.553.8272.6682.2888.6982.5165.5975.26
macbert4mdcspell_v371.7196.4368.0759.3678.8150.0748.6774.5179.0387.1681.3164.2972.76
macbert4mdcspell_v1_rethink269.6492.467.9957.6977.4950.3853.9669.3584.6588.2670.9656.0566.54
macbert4mdcspell_v2_rethink272.5495.5965.5458.0175.8649.6755.5672.7884.6590.7880.9365.7475.39
macbert4mdcspell_v3_rethink271.8295.0567.4862.1978.055.249.574.2681.7287.5676.7562.9671.12

2.2 acc(common_cor_acc)

model/common_cor_accavggen_de3lemon_v2gen_passagetext_proofgen_xxqgfaspelllomo_tetmcsc_tetecspellsighan2013sighan2014sighan2015
shibing624/macbert4csc-base-chinese48.2626.9628.6834.1655.2928.3822.260.9657.1667.7355.968.9372.73
shibing624/chinese-text-correction-1.5b46.0915.8281.2922.9682.1719.0412.850.296.489.1322.827.8732.55
twnlp/ChineseErrorCorrector3-4B51.8517.8781.227.3248.1723.4420.877.1699.9276.649.047.1853.55
relm_v151.981.7136.1837.0463.9929.3422.951.9874.176.050.345.7653.45
bert4csc_v160.7688.2145.9643.1368.9735.034.065.8673.2681.864.561.1167.27
macbert4csc_v165.3493.5649.7644.9874.6436.137.073.083.686.8769.262.6272.73
macbert4csc_v265.2293.6950.1444.9274.6436.2637.072.7283.6686.9368.562.4371.73
macbert4mdcspell_v167.1593.0954.847.7178.0939.5238.871.9284.7888.2773.263.2872.36
macbert4mdcspell_v268.3193.0950.0548.7275.7440.5238.976.984.889.7371.071.9478.36
macbert4mdcspell_v368.0993.1152.4253.9177.8945.2834.276.8282.588.1369.268.8374.82
macbert4mdcspell_v1_rethink265.0485.8852.4251.6976.2344.5238.970.7886.4888.9355.859.9868.91
macbert4mdcspell_v2_rethink269.1491.5649.7653.0175.6744.8440.576.9886.5691.4768.872.0378.45
macbert4mdcspell_v3_rethink267.8490.5751.7656.2477.1949.1634.976.6484.488.4763.167.9873.64

2.3 acc(acc_true, thr=0.75)

model/accavgacc_rmrbacc_xxqg
shibing624/macbert4csc-base-chinese99.2499.2299.26
shibing624/chinese-text-correction-1.5b82.077.1486.86
twnlp/ChineseErrorCorrector3-4B77.0376.9677.1
relm_v193.4790.2196.74
bert4csc_v198.7198.3699.06
macbert4csc_v197.7296.7298.72
macbert4csc_v297.8996.9898.8
macbert4mdcspell_v197.7596.5198.98
macbert4mdcspell_v299.5499.2299.86
macbert4mdcspell_v398.8598.3299.38
macbert4mdcspell_v1_rethink292.7888.3197.24
macbert4mdcspell_v2_rethink298.1596.7299.58
macbert4mdcspell_v3_rethink298.8598.3299.38

数据集_alipayseq

model/common_cor_f1alipayseq
shibing624/macbert4csc15.36
twnlp/ChineseErrorCorrector3-4B42.84
bert4csc_v142.23
macbert4csc_v148.45
macbert4csc_v245.60
macbert4mdcspell_v148.97
macbert4mdcspell_v250.41
macbert4mdcspell_v350.14

数据集_古诗-文言文数据集测评

model/common_cor_f1detcor
shibing624/macbert4csc-base-chinese44.127.48
macbert4mdcspell_v158.9812.43
macbert4mdcspell_v250.6110.40
macbert4mdcspell_v373.2447.41

二、结论(Conclusion)

1.macbert4csc_v1/macbert4csc_v2/macbert4mdcspell_v1等模型使用多种领域数据训练, 比较均衡, 也适合作为第一步的预训练模型, 可用于专有领域数据的继续微调;
2.比较macbert4csc_pycorrector/bertbase4csc_v1/macbert4csc_v2/macbert4mdcspell_v1, 观察表2.3, 可以发现训练数据越多, 准确率提升的同时, 误纠率也会稍微高一些;
3.MFT(Mask-Correct)依旧有效, 不过对于数据量足够的情形提升不明显, 可能也是误纠率升高的一个重要原因;
4.训练数据中也存在文言文数据, 训练好的模型也支持文言文纠错;
5.训练好的模型对"地得的"等高频错误具有较高的识别率和纠错率;
6.macbert4mdcspell_v2的MFT只70%的时间no-error-mask(0.15), 15%的时间target-to-target, 15%的时间不mask;
7.macbert4mdcspell_v3的MFT只85%的时间no-error-mask(0.15), 5%的时间target-to-target, 10%的时间不mask;(强化古文/现代文, 但降target-to-target比例太多使其比v2过纠多一点点)

三、调用(Usage)

3.1 使用macro-correct

import os
os.environ["MACRO_CORRECT_FLAG_CSC_TOKEN"] = "1"
from macro_correct import correct
### 默认纠错(list输入)
text_list = ["真麻烦你了。希望你们好好的跳无",
             "少先队员因该为老人让坐",
             "机七学习是人工智能领遇最能体现智能的一个分知",
             "一只小鱼船浮在平净的河面上"
             ]
text_csc = correct(text_list)
print("默认纠错(list输入):")
for res_i in text_csc:
    print(res_i)
print("#" * 128)

"""
默认纠错(list输入):
{'index': 0, 'source': '真麻烦你了。希望你们好好的跳无', 'target': '真麻烦你了。希望你们好好地跳舞', 'errors': [['的', '地', 12, 0.6584], ['无', '舞', 14, 1.0]]}
{'index': 1, 'source': '少先队员因该为老人让坐', 'target': '少先队员应该为老人让坐', 'errors': [['因', '应', 4, 0.995]]}
{'index': 2, 'source': '机七学习是人工智能领遇最能体现智能的一个分知', 'target': '机器学习是人工智能领域最能体现智能的一个分支', 'errors': [['七', '器', 1, 0.9998], ['遇', '域', 10, 0.9999], ['知', '支', 21, 1.0]]}
{'index': 3, 'source': '一只小鱼船浮在平净的河面上', 'target': '一只小鱼船浮在平静的河面上', 'errors': [['净', '静', 8, 0.9961]]}
"""

3.2 使用 transformers

# !/usr/bin/python
# -*- coding: utf-8 -*-
# @time    : 2021/2/29 21:41
# @author  : Mo
# @function: transformers直接加载bert类模型测试


import traceback
import time
import sys
import os
os.environ["USE_TORCH"] = "1"
from transformers import BertConfig, BertTokenizer, BertForMaskedLM
import torch

# pretrained_model_name_or_path = "shibing624/macbert4csc-base-chinese"
pretrained_model_name_or_path = "Macropodus/macbert4mdcspell_v3"
# pretrained_model_name_or_path = "Macropodus/macbert4mdcspell_v2"
# pretrained_model_name_or_path = "Macropodus/macbert4mdcspell_v1"
# pretrained_model_name_or_path = "Macropodus/macbert4csc_v1"
# pretrained_model_name_or_path = "Macropodus/macbert4csc_v2"
# pretrained_model_name_or_path = "Macropodus/bert4csc_v1"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
max_len = 128

print("load model, please wait a few minute!")
tokenizer = BertTokenizer.from_pretrained(pretrained_model_name_or_path)
bert_config = BertConfig.from_pretrained(pretrained_model_name_or_path)
model = BertForMaskedLM.from_pretrained(pretrained_model_name_or_path)
model.to(device)
print("load model success!")

texts = [
    "机七学习是人工智能领遇最能体现智能的一个分知",
    "我是练习时长两念半的鸽仁练习生蔡徐坤",
    "真麻烦你了。希望你们好好的跳无",
    "他法语说的很好,的语也不错",
    "遇到一位很棒的奴生跟我疗天",
    "我们为这个目标努力不解",
]
len_mid = min(max_len, max([len(t)+2 for t in texts]))

with torch.no_grad():
    outputs = model(**tokenizer(texts, padding=True, max_length=len_mid,
                                return_tensors="pt").to(device))

def get_errors(source, target):
    """   极简方法获取 errors   """
    len_min = min(len(source), len(target))
    errors = []
    for idx in range(len_min):
        if source[idx] != target[idx]:
            errors.append([source[idx], target[idx], idx])
    return errors

result = []
for probs, source in zip(outputs.logits, texts):
    ids = torch.argmax(probs, dim=-1)
    tokens_space = tokenizer.decode(ids[1:-1], skip_special_tokens=False)
    text_new = tokens_space.replace(" ", "")
    target = text_new[:len(source)]
    errors = get_errors(source, target)
    print(source, " => ", target, errors)
    result.append([target, errors])
print(result)
"""
机七学习是人工智能领遇最能体现智能的一个分知  =>  机器学习是人工智能领域最能体现智能的一个分支 [['七', '器', 1], ['遇', '域', 10], ['知', '支', 21]]
我是练习时长两念半的鸽仁练习生蔡徐坤  =>  我是练习时长两年半的个人练习生蔡徐坤 [['念', '年', 7], ['鸽', '个', 10], ['仁', '人', 11]]
真麻烦你了。希望你们好好的跳无  =>  真麻烦你了。希望你们好好地跳舞 [['的', '地', 12], ['无', '舞', 14]]
他法语说的很好,的语也不错  =>  他法语说得很好,德语也不错 [['的', '得', 4], ['的', '德', 8]]
遇到一位很棒的奴生跟我疗天  =>  遇到一位很棒的女生跟我聊天 [['奴', '女', 7], ['疗', '聊', 11]]
我们为这个目标努力不解  =>  我们为这个目标努力不懈 [['解', '懈', 10]]
"""

四、论文(Paper)

五、参考(Refer)

六、引用(Cite)

For citing this work, you can refer to the present GitHub project. For example, with BibTeX:

@software{macro-correct,
    url = {https://github.com/yongzhuo/macro-correct},
    author = {Yongzhuo Mo},
    title = {macro-correct},
    year = {2025}

Contributors

Macropodus

4 commits