Skip to content
Projects

TW-NLP/ChineseErrorCorrector

View on GitHub

TW-NLP/ChineseErrorCorrector has 662 GitHub stars and 48 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-15 13:57 UTC. Last push 2026-08-16.

How these counts are measured

Measured star growth

in 24h
0
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

About

一个面向中文文本纠错任务的综合平台,集学术研究、模型训练、模型评测和推理部署于一体,文本纠错新Sota。( 2026 ACL Main Oral )

Developer Tools

README_EN.md

Original

Chinese Spelling and Grammar Correction


Introduction

This project supports Chinese spelling and grammar error correction. We have also open-sourced an augmentation tool for spelling and grammar errors, large model training code, and a collection of related papers on text correction. We are honored to have won the CCL 2024 championship 🏆 (view paper), the 2023 NLPCC-NaCGEC Correction Task championship 🏆, and the 2022 FCGEC Correction Task championship 🏆. If you find this project helpful, please give it a star ✨.

🔥🔥🔥 News

[2025/08/08] Released a general-purpose text evaluation tool 🎉, which allows for text correction evaluation even with low resources.

[2025/08/06] Published a continuously updated list of papers related to text correction 🥳, to facilitate research and study.

[2025/08/01] Released twnlp/ChineseErrorCorrector3-4B 🎉🎉🎉, with comprehensively improved generalization capabilities. It ranks first among all open-source models. See the leaderboard for details.

[2025/05/01] Based on a suggestion, we have retrained the correction model (ChineseErrorCorrector2-7B) and have completely open-sourced the training steps to support result reproducibility. See the tutorial for reproduction.

[2025/03/17] Updated batch processing for incorrect text. See transformers batch inference and VLLM batch inference.

[2025/03/10] The model now supports multiple inference methods, including transformers, VLLM, and modelscope.

[2025/02/25] 🎉🎉🎉 After multiple rounds of iterative training on 2 million correction data points, we released twnlp/ChineseErrorCorrector2-7B. On the official NaCGEC-2023NLPCC test set, it surpassed the first-place model from Huawei by 10 points, taking a significant lead. Technical details.

[2025/02] For easier deployment, we released twnlp/ChineseErrorCorrector-1.5B, trained on 380,000 open-source spelling data points.

[2025/01] Using 380,000 open-source spelling data points and based on Qwen2.5, we trained a Chinese spelling correction model that supports corrections for phonologically and visually similar characters, releasing twnlp/ChineseErrorCorrector-7B and twnlp/ChineseErrorCorrector-32B-LORA.

[2024/06] v0.1.0 release: 🎉🎉🎉 Open-sourced a one-click grammatical error augmentation tool. This tool can augment text with 14 types of grammatical errors. Users in different fields can use their own data to replace errors and train custom grammar and spelling models. See Tag-v0.1.0 for details.

Model List

Model Name Correction Type Description
twnlp/ChineseErrorCorrector3-4B Grammar + Spelling Fully trained on 2 million correction data points. Suitable for both grammar and spelling correction. Best performance, recommended for use.
twnlp/ChineseErrorCorrector2-7B Grammar + Spelling Trained with multiple iterative rounds on 2 million correction data points. Suitable for grammar and spelling correction, with good performance.
twnlp/ChineseErrorCorrector-7B Spelling Trained on 380,000 open-source spelling data points. Supports correction of phonologically and visually similar character errors. Good performance on spelling correction.
twnlp/ChineseErrorCorrector-1.5B Spelling Trained on 380,000 open-source spelling data points. Supports correction of phonologically and visually similar character errors. Fair performance on spelling correction.

Datasets

Dataset Name Data Link Size and Category Description
ChinseseErrorCorrectData twnlp/ChinseseErrorCorrectData 2 million Training dataset for ChineseErrorCorrector2-7B.
CSC (Spelling Correction) twnlp/csc_data W271K(279,816) Medical(39,303) Lemon(22,259) ECSpell(6,688) CSCD(35,001) Chinese spelling correction datasets.
CGC (Grammar Correction) twnlp/cgc_data CGED(20,449) FCGEC(37,354) MuCGEC(2,467) NaCGEC(7,568) Chinese grammar correction datasets.
Lang8+HSK twnlp/lang8_hsk 1,568,885 A mixed dataset of Chinese spelling and grammar errors.

Evaluation (Generalization)

Evaluation Results

  • Evaluation Metric: F1
  • CSC (Chinese Spelling Correction): Models that can handle aligned errors such as those based on phonological or visual similarity.
  • CTC (Chinese Text Correction): Models that support spelling and grammar corrections, including unaligned errors like extra or missing characters.
  • GPU: Tesla V100, 32 GB VRAM
Model Name Model Link Base Model Avg SIGHAN-2015 EC-LAW MCSC GPU QPS
Kenlm-CSC shibing624/chinese-kenlm-klm kenlm 0.3409 0.3147 0.3763 0.3317 CPU 9
Mengzi-T5-CSC shibing624/mengzi-t5-base-chinese-correction mengzi-t5-base 0.3984 0.7758 0.3156 0.1039 GPU 214
ERNIE-CSC PaddleNLP/ernie-csc PaddlePaddle/ernie-1.0-base-zh 0.4353 0.8383 0.3357 0.1318 GPU 114
MacBERT-CSC shibing624/macbert4csc-base-chinese hfl/chinese-macbert-base 0.3993 0.8314 0.1610 0.2055 GPU 224
ChatGLM3-6B-CSC shibing624/chatglm3-6b-csc-chinese-lora THUDM/chatglm3-6b 0.4538 0.6572 0.4369 0.2672 GPU 3
Qwen2.5-1.5B-CTC shibing624/chinese-text-correction-1.5b Qwen/Qwen2.5-1.5B-Instruct 0.6802 0.3032 0.7846 0.9529 GPU 6
Qwen2.5-7B-CTC shibing624/chinese-text-correction-7b Qwen/Qwen2.5-7B-Instruct 0.8225 0.4917 0.9798 0.9959 GPU 3
**QQwen3-4B-CTC (Our) twnlp/ChineseErrorCorrector3-4B Qwen/Qwen3-4B 0.8521 0.6340 0.9360 0.9864 GPU 5

Text Correction Competition Evaluation (Two-Time Champions 🏆)

NaCGEC Dataset

🏆

Model Name Model Link Prec Rec F0.5
twnlp/ChineseErrorCorrector3-4B huggingface ; modelscope(China download) 0.542 0.3475 0.4874
HW_TSC_nlpcc2023_cgec (Huawei) Not open-sourced 0.5095 0.3129 0.4526
鱼饼啾啾Plus (Peking University) Not open-sourced 0.5708 0.1294 0.3394
CUHK_SU (The Chinese University of Hong Kong) Not open-sourced 0.3882 0.1558 0.2990

FCGEC Dataset

  • **Evaluation Metric: binary_f1

Evaluation 🏆

Usage

🤗 transformers

pip install transformers
from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed
set_seed(42)

model_name = "twnlp/ChineseErrorCorrector3-4B"

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

prompt = "You are a text correction expert. Correct the grammatical errors in the input sentence and output the corrected sentence. The input sentence is: "
text_input = "对待每一项工作都要一丝不够。" # Incorrect: "Approach every task with a thread of not enough."
messages = [
    {"role": "user", "content": prompt + text_input}
]
text = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True,
        enable_thinking=False # Switches between thinking and non-thinking modes. Default is True.
    )
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response) # Corrected output: 对待每一项工作都要一丝不苟。 (Approach every task meticulously.)

VLLM

pip install transformers
pip install vllm==0.8.5
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams

# Initialize the tokenizer
tokenizer = AutoTokenizer.from_pretrained("twnlp/ChineseErrorCorrector3-4B")

# Pass the default decoding hyperparameters of twnlp/ChineseErrorCorrector3-4B
# max_tokens is for the maximum length for generation.
sampling_params = SamplingParams(seed=42, max_tokens=512)

# Input the model name or path. Can be GPTQ or AWQ models.
llm = LLM(model="twnlp/ChineseErrorCorrector3-4B")

# Prepare your prompts
text_input = "对待每一项工作都要一丝不够。" # Incorrect
messages = [
    {"role": "user", "content": "You are a text correction expert. Correct the grammatical errors in the input sentence and output the corrected sentence. The input sentence is: " + text_input}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True,
    enable_thinking=False
)

# generate outputs
outputs = llm.generate([text], sampling_params)

# Print the outputs.
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

VLLM Asynchronous Batch Inference (Recommended for Production)

  • Clone the repo
git clone https://github.com/TW-NLP/ChineseErrorCorrector
cd ChineseErrorCorrector
conda create -n zh_correct -y python=3.10
conda activate zh_correct
pip install -r requirements.txt
# If you are in mainland China, you can use a mirror:
# pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com
# Modify config.py
# (1) Change DEFAULT_CKPT_PATH according to your model. Default is twnlp/ChineseErrorCorrector3-4B.
#     (Download the model and place it in ChineseErrorCorrector/pre_model/twnlp/ChineseErrorCorrector3-4B)
# (2) Set TextCorrectConfig's USE_VLLM = True

# Batch prediction
python main.py

Transformers Batch Inference

  • Clone the repo
git clone https://github.com/TW-NLP/ChineseErrorCorrector
cd ChineseErrorCorrector
conda create -n zh_correct -y python=3.10
conda activate zh_correct
pip install -r requirements.txt
# If you are in mainland China, you can use a mirror:
# pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com
# Modify config.py
# (1) Change DEFAULT_CKPT_PATH according to your model. Default is twnlp/ChineseErrorCorrector3-4B.
# (2) Set TextCorrectConfig's USE_VLLM = False

# Batch prediction
python main.py

# Output:
'''
[{'source': '对待每一项工作都要一丝不够。', 'target': '对待每一项工作都要一丝不苟。', 'errors': [('够', '苟', 12)]}, {'source': '大约半个小时左右', 'target': '大约半个小时', 'errors': [('左右', '', 6)]}]
'''

🤖 modelscope

pip install modelscope
from modelscope import AutoModelForCausalLM, AutoTokenizer

model_name = "tiannlp/ChineseErrorCorrector3-4B" # Note the model name is slightly different on modelscope

model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

prompt = "You are a text correction expert. Correct the grammatical errors in the input sentence and output the corrected sentence. The input sentence is: "
text_input = "对待每一项工作都要一丝不够。" # Incorrect
messages = [
    {"role": "user", "content": prompt + text_input}
]
text = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True,
        enable_thinking=False # Switches between thinking and non-thinking modes. Default is True.
    )
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response) # Corrected output

Citation

If this work is helpful, please kindly cite as:

@inproceedings{wei2024中小学作文语法错误检测,
  title={Research on Automated Methods for Grammatical Error Detection, Sentence Revision, and Fluency Rating in Primary and Secondary School Compositions},
  author={Wei, Tian},
  booktitle={Proceedings of the 23rd Chinese National Conference on Computational Linguistics (Volume 3: Evaluations)},
  pages={278--284},
  year={2024}
}

Contributing

Contributions of all kinds are welcome: reporting issues, improving documentation, adding data, fixing bugs, and submitting new features. Please read CONTRIBUTING.md for the Issue / Pull Request guidelines and code style before you start.

License

This project is released under the Apache-2.0 License. You are free to use it for research and commercial purposes; please retain the copyright and license notices.

References