---
title: ChineseErrorCorrector2-7B
canonical_url: "https://www.modelscope.cn/models/tiannlp/ChineseErrorCorrector2-7B"
md_url: "https://www.modelscope.cn/models/tiannlp/ChineseErrorCorrector2-7B.md"
repository: tiannlp/ChineseErrorCorrector2-7B
last_updated: 2025-08-04
pipeline_tag: text-error-correction
tasks:
  - text-error-correction
model_type:
  - qwen2
architectures:
  - Qwen2ForCausalLM
parameters: 7.6B
tensor_type:
  - BF16
library_name:
  - transformer
  - safetensors
  - pytorch
frameworks:
  - Pytorch
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy 0.9.1"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 2951
stars: 14
---

# ChineseErrorCorrector2-7B

> ChineseErrorCorrector2-7B - tiannlp 在 ModelScope 开源的模型。使用200万纠错数据进行多轮迭代训练，发布了ChineseErrorCorrector2-7B，在 NaCGEC-2023NLPCC官方评测数据集上，超越第一名华为17个点，遥遥领先，推荐使用

tiannlp/ChineseErrorCorrector2-7B 是 ModelScope 魔搭社区上的 7.6B 参数text-error-correction模型，可用 deploy_task text/emb、lmdeploy 0.9.1、lmdeploy_turbomind 0.9.1 部署。

- **Repository**: tiannlp/ChineseErrorCorrector2-7B
- **Tasks**: text-error-correction
- **Parameters**: 7.6B
- **Inference backends**: deploy_task text/emb, lmdeploy 0.9.1, lmdeploy_turbomind 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Downloads**: 2951
- **Stars**: 14
- **Last updated**: 2025-08-04

Source: https://www.modelscope.cn/models/tiannlp/ChineseErrorCorrector2-7B

---

#  中文拼写和语法纠错




-----------------
## 项目地址

https://github.com/TW-NLP/ChineseErrorCorrector

后续会在项目中继续更新纠错模型、量化模型和推理方式。

## 🔥🔥🔥 新闻
[2025/08/06] 发布[twnlp/ChineseErrorCorrector3-4B](https://huggingface.co/twnlp/ChineseErrorCorrector3-4B) 🎉🎉🎉，泛化性更好，性能更高。

[2025/03/12] 为了方便使用，基于AWQ进行量化，发布 [twnlp/ChineseErrorCorrector2-7B-AWQ](https://huggingface.co/twnlp/ChineseErrorCorrector2-7B-AWQ)，在单张T4(16G)显卡上即可运行😄,transformers推理占用6G显存, [具体详情](https://github.com/TW-NLP/ChineseErrorCorrector)


## 文本纠错评测（拼写错误+语法错误）
- 评估工具：ChERRANT  [评测工具](https://github.com/HillZhang1999/MuCGEC)
- 评估数据：[NaCGEC](https://github.com/masr2000/NaCGEC)
- 评估指标：F1-0.5


| Model Name       | Model Link                                                                                                              |    Prec     | Rec | F0.5 |
|:-----------------|:---------------------------------------------------------------|:-----------|:------------|:-------|
|  twnlp/ChineseErrorCorrector2-7B | https://huggingface.co/twnlp/ChineseErrorCorrector2-7B       |  0.5686     | 0.57      | 0.5689 |
|  HW_TSC_nlpcc2023_cgec(华为) |   未开源     |  0.5095     | 0.3129      | 0.4526 |
| 鱼饼啾啾Plus |   未开源     |  0.5708     | 0.1294      | 0.3394 |
| CUHK_SU |  未开源      |  0.3882     | 0.1558      | 0.2990 |
| CGEC++ |    未开源    |  0.2414     | 0.0735      | 0.1657 |
| zhao_jia |   未开源     |  0.1719     | 0.1478      | 0.1665 |


## 使用
### transformers 

```shell
pip install transformers
```

```shell
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "twnlp/ChineseErrorCorrector2-7B"

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

prompt = "你是一个文本纠错专家，纠正输入句子中的语法错误，并输出正确的句子，输入句子为："
text_input = "对待每一项工作都要一丝不够。"
messages = [
    {"role": "user", "content": prompt + text_input}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=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)

```

### VLLM

```shell
pip install transformers
pip install vllm==0.3.3
```

```shell
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams

# Initialize the tokenizer
tokenizer = AutoTokenizer.from_pretrained("twnlp/ChineseErrorCorrector2-7B")

# Pass the default decoding hyperparameters of twnlp/ChineseErrorCorrector2-7B
# 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/ChineseErrorCorrector2-7B")

# Prepare your prompts
prompt = "对待每一项工作都要一丝不够。"
messages = [
    {"role": "user", "content": "你是一个文本纠错专家，纠正输入句子中的语法错误，并输出正确的句子，输入句子为："+prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)

# 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 异步推理
```shell
pip install -r requirements.txt
cd ChineseErrorCorrector

python main.py
```

### modelscope 

```shell
pip install modelscope
```

```shell
from modelscope import AutoModelForCausalLM, AutoTokenizer

model_name = "tiannlp/ChineseErrorCorrector2-7B"

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

prompt = "你是一个文本纠错专家，纠正输入句子中的语法错误，并输出正确的句子，输入句子为："
text_input = "对待每一项工作都要一丝不够。"
messages = [
    {"role": "user", "content": prompt + text_input}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=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)

```

## Citation

If this work is helpful, please kindly cite as:

```bibtex

@inproceedings{wei2024中小学作文语法错误检测,
  title={中小学作文语法错误检测, 病句改写与流畅性评级的自动化方法研究},
  author={Wei, Tian},
  booktitle={Proceedings of the 23rd Chinese National Conference on Computational Linguistics (Volume 3: Evaluations)},
  pages={278--284},
  year={2024}
}
```


## Star History

![Star History Chart](https://api.star-history.com/svg?repos=TW-NLP/ChineseErrorCorrector&type=Date)
