File size: 1,598 Bytes
93da7d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
language:
- zh
tags:
- chinese
- spelling-correction
- csc
- bert
- text-correction
library_name: pytorch
---

# BERTc-165M-CSC

BERTc-165M-CSC is a Chinese spelling correction model fine-tuned from
`Ismantic/BERTc-165M`. It uses a Modern BERTc encoder with two heads:

- correction head: tied to the input embedding matrix
- detection head: binary error detection

## Metrics

SIGHAN-15 sentence-level evaluation using the pycorrector-style 707-sample protocol:

- Sentence F1: **0.8308**
- Accuracy: **0.8416**
- Precision: **0.9516**
- Recall: **0.7373**
- TP/FP/FN/TN: 275 / 14 / 98 / 320

Training recipe:

- backbone: `Ismantic/BERTc-165M`
- epochs: 5
- batch size: 64
- learning rate: 5e-5
- warmup ratio: 0.1
- detection loss weight: 0.3
- inference threshold: 0.7
- max length: 128

## Files

- `model.safetensors`: CSC state dict. `cor_head.weight` is intentionally omitted and tied to `bert.embed.weight` by `csc_model.py`.
- `config.json`: BERTc backbone architecture.
- `csc_config.json`: task and metric metadata.
- `model.py`: Modern BERTc implementation.
- `csc_model.py`: CSC wrapper and batch correction helper.
- `piece.model`: tokenizer model; load with `piece_tokenizer` using `cn_dict="no"`.

## Usage

```python
from csc_model import BERTcForCSC, PieceCharTokenizer

tok = PieceCharTokenizer(".")
model = BERTcForCSC.from_pretrained(".")
texts = ["少先队员因该为老人让坐。"]
print(model.correct(texts, tok, threshold=0.7))
```

This is not a generative model. It performs same-length character replacement for
Chinese spelling correction.