Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
---
|
| 4 |
+
## Usage (HuggingFace Transformers)
|
| 5 |
+
Without [ChineseErrorCorrector](https://github.com/TW-NLP/ChineseErrorCorrector/tree/0.1.0), you can use the model like this:
|
| 6 |
+
|
| 7 |
+
First, you pass your input through the transformer model, then you get the generated sentence.
|
| 8 |
+
|
| 9 |
+
Install package:
|
| 10 |
+
```
|
| 11 |
+
pip install transformers
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
```python
|
| 15 |
+
# pip install transformers
|
| 16 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 17 |
+
checkpoint = "twnlp/ChineseErrorCorrector-7B"
|
| 18 |
+
|
| 19 |
+
device = "cuda" # for GPU usage or "cpu" for CPU usage
|
| 20 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 21 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
|
| 22 |
+
|
| 23 |
+
input_content = "你是一个拼写纠错专家,对原文进行错别字纠正,不要更改原文字数,原文为:\n少先队员因该为老人让坐。"
|
| 24 |
+
|
| 25 |
+
messages = [{"role": "user", "content": input_content}]
|
| 26 |
+
input_text=tokenizer.apply_chat_template(messages, tokenize=False)
|
| 27 |
+
|
| 28 |
+
print(input_text)
|
| 29 |
+
|
| 30 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
| 31 |
+
outputs = model.generate(inputs, max_new_tokens=1024, temperature=0, do_sample=False, repetition_penalty=1.08)
|
| 32 |
+
|
| 33 |
+
print(tokenizer.decode(outputs[0]))
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
output:
|
| 37 |
+
```shell
|
| 38 |
+
少先队员应该为老人让座。
|
| 39 |
+
```
|