Downloads · 30 days
25
0% of all-time downloads
twnlp/ChineseErrorCorrector2-7B
ChineseErrorCorrector2-7B is a machine learning model from twnlp. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Without ChineseErrorCorrector, you can use the model like this:
Downloads · 30 days
25
0% of all-time downloads
All-time downloads
9.3K
Public
Parameters
7.6B
44.6 GB on disk
Likes
6
Public
Click a slice to open those files.
.safetensors15.2 GB · 100%
From the Hugging Face model README
Without ChineseErrorCorrector, you can use the model like this:
First, you pass your input through the transformer model, then you get the generated sentence.
Install package:
pip install transformers
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)
output:
对待每一项工作都要一丝不苟。