from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "haowu11/ChineseErrorCorrector2-7B-SFT-GRPO"
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)
通知强调,针对近期部分地区高温干旱、农事用火增多、森林火灾频发的严峻形势,各地要切实抓好森林防火责任制的落实,严格管控野外生产生活用火,全力做好突发火情的应急处置。
license: apache-2.0