File size: 5,738 Bytes
7ee59ff 3df347e 7ee59ff b2f83ee 7ee59ff b2f83ee 7ee59ff 3df347e 7ee59ff 3df347e 7ee59ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
---
language: zh
license: apache-2.0
base_model: Morton-Li/QiDeBERTa-base
tags:
- deberta
- mlm
- chinese
- language-modeling
- robust-nlp
- general-purpose
- pretraining
- spelling-correction
- csc
- fine-tuning
- masked-language-modeling
---
# QiDeBERTa for Chinese Spelling Correction (CSC)
**Model Name**: `QiDeBERTa-CSC`
**Language**: Chinese
**任务方向**: 中文拼写纠错(Chinese Spelling Correction, CSC)
**Architecture**: DeBERTa V3 (modified)
**Author**: Morton Li
**License**: Apache-2.0
**Tags**: `deberta`, `mlm`, `chinese`, `language-modeling`, `robust-nlp`, `general-purpose`, `pretraining`, `spelling-correction`, `csc`, `fine-tuning`, `masked-language-modeling`
## Model Description
**QiDeBERTa-CSC** 是专为中文拼写纠错任务优化的语言模型,基于预训练模型 `QiDeBERTa-base` 进行多阶段精调,具备高鲁棒性与纠错精度。该模型支持纠正真实文本中的错别字,适用于内容审核、教育批改等场景。
本模型在多个主流拼写纠错评测基准(如 SIGHAN15、CSCD-NS)中显著优于现有主流拼写纠错模型,并通过 `Token-Level` 评估指标体系精准度量模型改错能力,避免常规评估体系算法与实际使用体验存在较大偏差的问题。
## Model Architecture
- 基础架构:DeBERTa V3
- 编码器层数:12层
- 隐藏维度:768
- 注意力头数:12
- 任务头:
- **MaskedLanguageModelingHead**
## Tokenizer
QiDeBERTa-CSC 沿用上游模型 **SentencePiece** 分词器,对《通用规范汉字表》**一级、二级、三级汉字**实现 **100% 字符覆盖率**。
> 分词器可通过 HuggingFace Tokenizer API 直接加载,无需额外训练。
## Pretraining Objectives
QiDeBERTa-CSC 使用 **Masked Language Modeling** 作为核心训练目标,配合**3.8M 条高质量样本** ,辅以合成数据样本以提高模型泛化能力。通过不同类型的任务头进行混合建模,模型具备良好的语义鲁棒性与改错精度。
此外,引入目标导向的训练损失调控机制,强化模型在错字与原始输出接近场景下的学习效果,进一步提升其泛用性能。
> 所有语料均为公开来源或基于合规机制采集经清洗与筛选,确保数据多样性与覆盖性。
## Evaluation
本模型评估采用 **Token-Level** 评估标准,强调精准、严谨、一致,避免常规评估指标算法与实际使用体验存在较大偏差的问题。该指标体系更贴近工业实际使用场景中的错误感知与容错要求,更能体现模型实际部署表现情况。
在该体系下进行 zero-shot 评估:
| Task | Dataset | Accuracy | F1 | Precision | Recall |
|------|------------------------------------------------------|----------|--------|-----------|--------|
| CSC | [SIGHAN15](https://aclanthology.org/W15-3106.pdf) | 98.79% | 68.86% | 69.41% | 68.32% |
| CSC | [CSCD-NS](https://aclanthology.org/2024.acl-long.10) | 99.39% | 63.71% | 64.67% | 63.84% |
> 在相同任务、相同平台、相同评分标准下,当前主流 SOTA 模型在 CSCD-NS zero-shot 测试中 F1 得分普遍低于 20%,QiDeBERTa 在鲁棒性与建模性能方面已具备优势。
## Training Details
- Optimizer: AdamW (`weight_decay=0.01`, LayerNorm & bias权重例外)
- Learning Rate: `3e-4`(任务头)warmup + 线性衰减,`1.5e-5`(编码器)warmup + 线性衰减
- Batch Size: 32 (平摊至每张显卡后)
- Mixed Precision: ✅ 支持 (fp16)
- Gradient Checkpointing: ✅ 支持
- Hardware: NVIDIA L40s GPU cluster
## How to Use
以下代码展示了如何使用模型进行推理并返回错别字位置与修正建议:
```python
from transformers import AutoTokenizer, AutoModel, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("Morton-Li/QiDeBERTa-CSC", trust_remote_code=True)
model = AutoModelForMaskedLM.from_pretrained("Morton-Li/QiDeBERTa-CSC", trust_remote_code=True)
# model = AutoModel.from_pretrained("Morton-Li/QiDeBERTa-CSC", trust_remote_code=True)
texts = [
"编码器模型不涉及自回归或迭代解码所以速度很快。",
"吸烟由害健康。" # 包含错字
]
outputs = model(**tokenizer(texts, padding=True, return_tensors='pt')) # MaskedLMOutput[logits, hidden_states, attentions]
pred_list = tokenizer.batch_decode(outputs.logits.argmax(dim=-1).cpu().tolist(), skip_special_tokens=True)
# 组装推理结果
results = []
for pred, orig in zip(pred_list, texts):
pred = pred[:len(orig)].replace(' ', '') # 对齐推理结果
diffs = [
{'index': i, 'input_character': o, 'correct_character': p}
for i, (o, p) in enumerate(zip(orig, pred)) if o != p
]
results.append({
'original': orig, # 原始文本
'correct': pred, # 纠正文本
'correction': diffs # 错别字列表
})
print(results)
"""
[{
'original': '编码器模型不涉及自回归或迭代解码所以速度很快。',
'correct': '编码器模型不涉及自回归或迭代解码所以速度很快。',
'correction': []
},
{
'original': '吸烟由害健康。',
'correct': '吸烟有害健康。',
'correction': [{
'index': 2,
'input_character': '由',
'correct_character': '有'
}]
}]
"""
```
## Citation
If you find this project useful in your research, publications, software development, or any other work, please cite it as follows:
```bibtex
@misc{QiDeBERTa-CSC,
author = {Morton Li},
title = {QiDeBERTa-CSC: A Chinese Spelling Correction Model Based on QiDeBERTa},
year = {2025},
}
```
## License
Apache License 2.0
|