AI SeedbankHelp preserve open and free AI for humanity's future

← All models

shibing624_macbert4csc-base-chinese

shibing624 · View on Hugging Face ↗

Get this model

Download TorrentMagnet Link

Seeders: · Leechers:

Model card

The complete upstream card, rendered from this payload's README.md — the same hash-verified bytes the torrent distributes. Images and off-site links are removed; the original card on Hugging Face carries them.


language:

  • zh tags:
  • bert
  • pytorch
  • zh
  • pycorrector license: apache-2.0 datasets:
  • shibing624/CSC library_name: transformers pipeline_tag: text-generation widget:
    • text: 少先队员因该为老人让坐

MacBERT for Chinese Spelling Correction(macbert4csc) Model

中文拼写纠错模型

macbert4csc-base-chinese evaluate SIGHAN2015 test data:

Correct-Precision Correct-Recall Correct-F1
Chararcter-level 93.72 86.40 89.91
Sentence-level 82.64 73.66 77.89

由于训练使用的数据使用了SIGHAN2015的训练集(复现paper),在SIGHAN2015的测试集上达到SOTA水平。

模型结构,魔改于softmaskedbert:

Usage

本项目开源在中文文本纠错项目:pycorrector,可支持macbert4csc模型,通过如下命令调用:

from pycorrector.macbert.macbert_corrector import MacBertCorrector

m = MacBertCorrector("shibing624/macbert4csc-base-chinese")

i = m.correct('今天新情很好')
print(i)

当然,你也可使用transformers调用:

import operator
import torch
from transformers import BertTokenizer, BertForMaskedLM
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

tokenizer = BertTokenizer.from_pretrained("shibing624/macbert4csc-base-chinese")
model = BertForMaskedLM.from_pretrained("shibing624/macbert4csc-base-chinese")
model.to(device)

texts = ["今天新情很好", "你找到你最喜欢的工作,我也很高心。"]
with torch.no_grad():
    outputs = model(**tokenizer(texts, padding=True, return_tensors='pt').to(device))

def get_errors(corrected_text, origin_text):
    sub_details = []
    for i, ori_char in enumerate(origin_text):
        if ori_char in [' ', '“', '”', '‘', '’', '琊', '\n', '…', '—', '擤']:
            # add unk word
            corrected_text = corrected_text[:i] + ori_char + corrected_text[i:]
            continue
        if i >= len(corrected_text):
            continue
        if ori_char != corrected_text[i]:
            if ori_char.lower() == corrected_text[i]:
                # pass english upper char
                corrected_text = corrected_text[:i] + ori_char + corrected_text[i + 1:]
                continue
            sub_details.append((ori_char, corrected_text[i], i, i + 1))
    sub_details = sorted(sub_details, key=operator.itemgetter(2))
    return corrected_text, sub_details

result = []
for ids, text in zip(outputs.logits, texts):
    _text = tokenizer.decode(torch.argmax(ids, dim=-1), skip_special_tokens=True).replace(' ', '')
    corrected_text = _text[:len(text)]
    corrected_text, details = get_errors(corrected_text, text)
    print(text, ' => ', corrected_text, details)
    result.append((corrected_text, details))
print(result)

output:

今天新情很好  =>  今天心情很好 [('新', '心', 2, 3)]
你找到你最喜欢的工作,我也很高心。  =>  你找到你最喜欢的工作,我也很高兴。 [('心', '兴', 15, 16)]

模型文件组成:

macbert4csc-base-chinese
    ├── config.json
    ├── added_tokens.json
    ├── pytorch_model.bin
    ├── special_tokens_map.json
    ├── tokenizer_config.json
    └── vocab.txt

训练数据集

SIGHAN+Wang271K中文纠错数据集

数据集 语料 下载链接 压缩包大小
SIGHAN+Wang271K中文纠错数据集 SIGHAN+Wang271K(27万条) 百度网盘(密码01b9) 106M
原始SIGHAN数据集 SIGHAN13 14 15 官方csc.html 339K
原始Wang271K数据集 Wang271K Automatic-Corpus-Generation dimmywang提供 93M

SIGHAN+Wang271K中文纠错数据集,数据格式:

[
    {
        "id": "B2-4029-3",
        "original_text": "晚间会听到嗓音,白天的时候大家都不会太在意,但是在睡觉的时候这嗓音成为大家的恶梦。",
        "wrong_ids": [
            5,
            31
        ],
        "correct_text": "晚间会听到噪音,白天的时候大家都不会太在意,但是在睡觉的时候这噪音成为大家的恶梦。"
    },
]
macbert4csc
    ├── config.json
    ├── pytorch_model.bin
    ├── special_tokens_map.json
    ├── tokenizer_config.json
    └── vocab.txt

如果需要训练macbert4csc,请参考https://github.com/shibing624/pycorrector/tree/master/pycorrector/macbert

About MacBERT

MacBERT is an improved BERT with novel MLM as correction pre-training task, which mitigates the discrepancy of pre-training and fine-tuning.

Here is an example of our pre-training task.

task Example
Original Sentence we use a language model to predict the probability of the next word.
MLM we use a language [M] to [M] ##di ##ct the pro [M] ##bility of the next word .
Whole word masking we use a language [M] to [M] [M] [M] the [M] [M] [M] of the next word .
N-gram masking we use a [M] [M] to [M] [M] [M] the [M] [M] [M] [M] [M] next word .
MLM as correction we use a text system to ca ##lc ##ulate the po ##si ##bility of the next word .

Except for the new pre-training task, we also incorporate the following techniques.

  • Whole Word Masking (WWM)
  • N-gram masking
  • Sentence-Order Prediction (SOP)

Note that our MacBERT can be directly replaced with the original BERT as there is no differences in the main neural architecture.

For more technical details, please check our paper: Revisiting Pre-trained Models for Chinese Natural Language Processing

Citation

@software{pycorrector,
  author = {Xu Ming},
  title = {pycorrector: Text Error Correction Tool},
  year = {2021},
  url = {https://github.com/shibing624/pycorrector},
}

Magnet link

Opens the swarm directly in your torrent client — no file download needed. Copy-paste works too:

magnet:?xt=urn:btih:ece7a03125b024f7c182ca1c4b030ad6d60d1cfc&dn=shibing624_macbert4csc-base-chinese

Open magnet in torrent client · infohash ece7a03125b024f7c182ca1c4b030ad6d60d1cfc

Files & hashes

PathSizesha1sha256
README.md6.1 KB (6,259 B)2f68766a59a4996abf07f46dde8355d3a4d6d6093e977aef5f9c5b69d1c8f7710283b0323f7869571f7f3d23588f3f6d14adc389
added_tokens.json2 B (2 B)9e26dfeeb6e641a33dae4961196235bdb965b21b44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a
arch1.png135.6 KB (138,872 B)7901be12cd1a12557f3ad16b5792e41edba89aabe426b6ec7d967a287f0af16fdc896dbcf863054ac839ada67d71d8946029b457
config.json659 B (659 B)18c37980ba95eed529b58cffc23bcce90dc0108e648c8a2b51c12551f94bae19a66c21a59c9bd8aa0ebb99f2a0af7236cdb99daa
model.safetensors390.2 MB (409,189,104 B)af30e3689425b32873bb59e26b91d7daeb7d50fe73df11fd36fb7595aa29fb04182bebe108793357cb577c0bbe35f9ab0a8635e4
onnx/config.json845 B (845 B)f51a0c2c7c3b7dda92d549dc42354b2a8e78eaed13467683cd8734e2ee56512aeaa95e2b8a482d9882fb6acbe625374ae8157dee
onnx/generation_config.json90 B (90 B)65f5324ba89ef52c3ca6ace8012f1e5fa30a8fcd88e1219700f3caab181e2dda748de31beacffc7ecd0e3ab08d425d8147cd5cd0
onnx/special_tokens_map.json125 B (125 B)a8b3208c2884c4efb86e49300fdd3dc877220cdfb6d346be366a7d1d48332dbc9fdf3bf8960b5d879522b7799ddba59e76237ee3
onnx/tokenizer.json428.8 KB (439,124 B)15df791881f91e7963c9e0d704de2f2037baa0027dfbf1966ebf99d471c3796e9b457329d2b2182b817e144f1e904b957745c839
onnx/tokenizer_config.json394 B (394 B)42046bd361a033a24264dc41de1fe6cafd68072fe1790949631401af1bfb6c9c7aeec7fcf612e274d73579d99f704faea40c8ba7
onnx/vocab.txt107.0 KB (109,540 B)ca4f9781030019ab9b253c6dcb8c7878b6dc87a545bbac6b341c319adc98a532532882e91a9cefc0329aa57bac9ae761c27b291c
pytorch_model.bin390.3 MB (409,232,875 B)eab9ccdc95c8c4e7be4ffc1f9108879c0bc517f637a03fe0f103b25664f46fb65dbe520ffc63cc99c06ad679211102dbb7b5c9ed
special_tokens_map.json112 B (112 B)e7b0375001f109a6b8873d756ad4f7bbb15fbaa5303df45a03609e4ead04bc3dc1536d0ab19b5358db685b6f3da123d05ec200e3
tokenizer_config.json330 B (330 B)40893ac2dca282b4022a0d3be604f47adb05d4ed64523a761a0a0f58999c71432f6ff26c7d3c413d46e54180ba5ceb2e1b5cd042
vocab.txt107.0 KB (109,540 B)ca4f9781030019ab9b253c6dcb8c7878b6dc87a545bbac6b341c319adc98a532532882e91a9cefc0329aa57bac9ae761c27b291c

Cite this release

Canonical URL
https://aiseedbank.org/models/shibing624_macbert4csc-base-chinese/
Slug
shibing624_macbert4csc-base-chinese
Infohash
ece7a03125b024f7c182ca1c4b030ad6d60d1cfc
License
apache-2.0
Signing key fingerprint
85a3b32c3712427b

Every file carries a locally computed sha256 — verify a download against the signed sums: shibing624_macbert4csc-base-chinese.SHA256SUMS (+ minisign signature).

Provenance

Upstream repositoryshibing624/macbert4csc-base-chinese
Revision (pinned)615e6e09ef9a69ec487bc7c641ec3a311e2c11b9
Fetched at2026-09-04T05:39:31Z
License at fetchapache-2.0
Snapshot toolhuggingface · seedbank 0.1.0

Trackers

✓ verified · rehash-vs-hf-metadata at 2026-09-04T05:39:42Z

apache-2.0781.3 MB (819,227,871 bytes)transformerspytorchonnxsafetensorsbertfill-maskpycorrectortext-generationendpoints_compatible1 language (zh)paper: 2004.13922