Chatglm3 6b Csc Chinese Lora
基于ChatGLM3-6B的中文拼写纠错LoRA微调模型,具备高准确率的文本纠错能力,同时支持句子润色和改写功能。
下载量 42
发布时间 : 11/2/2023
模型简介
该模型是针对中文文本拼写纠错任务开发的LoRA微调模型,基于THUDM/chatglm3-6b大语言模型,能够有效识别并纠正中文文本中的拼写错误,适用于各类文本校对场景。
模型特点
高准确率纠错
在CSC测试集上表现出色,能够准确识别并纠正中文拼写错误。
句子润色功能
不仅能纠错,还能对句子进行润色和改写,提升文本质量。
LoRA微调
采用LoRA技术对ChatGLM3-6B进行高效微调,保持原模型能力的同时提升纠错性能。
模型能力
中文拼写纠错
文本润色
句子改写
使用案例
文本校对
学生作文纠错
自动检测并纠正学生作文中的拼写错误
少先队员因该为老人让坐。 → 少先队员应该为老人让座。
正式文件校对
对正式文件进行拼写检查,确保文本准确性
内容创作辅助
文本润色
对已有文本进行优化改写,提升表达质量
🚀 ChatGLM3-6B中文纠错LoRA模型
本模型是基于ChatGLM3-6B的中文纠错LoRA模型,在CSC测试集上有高纠错准确率。它不仅能纠错,还具备句子润色和改写功能,能带来超出预期的效果。
🚀 快速开始
安装依赖
使用此模型前,需要安装相关的Python库。可以通过以下命令进行安装:
pip install -U pycorrector
或
pip install transformers
调用示例
使用pycorrector
库调用
from pycorrector import GptCorrector
model = GptCorrector("THUDM/chatglm3-6b", "chatglm", peft_name="shibing624/chatglm3-6b-csc-chinese-lora")
r = model.correct_batch(["少先队员因该为老人让坐。"])
print(r) # ['少先队员应该为老人让座。']
直接使用HuggingFace Transformers调用
import os
import torch
from peft import PeftModel
from transformers import AutoTokenizer, AutoModel
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True).half().cuda()
model = PeftModel.from_pretrained(model, "shibing624/chatglm3-6b-csc-chinese-lora")
sents = ['对下面文本纠错\n\n少先队员因该为老人让坐。',
'对下面文本纠错\n\n下个星期,我跟我朋唷打算去法国玩儿。']
def get_prompt(user_query):
vicuna_prompt = "A chat between a curious user and an artificial intelligence assistant. " \
"The assistant gives helpful, detailed, and polite answers to the user's questions. " \
"USER: {query} ASSISTANT:"
return vicuna_prompt.format(query=user_query)
for s in sents:
q = get_prompt(s)
input_ids = tokenizer(q).input_ids
generation_kwargs = dict(max_new_tokens=128, do_sample=True, temperature=0.8)
outputs = model.generate(input_ids=torch.as_tensor([input_ids]).to('cuda:0'), **generation_kwargs)
output_tensor = outputs[0][len(input_ids):]
response = tokenizer.decode(output_tensor, skip_special_tokens=True)
print(response)
输出示例
少先队员应该为老人让座。
下个星期,我跟我朋友打算去法国玩儿。
✨ 主要特性
- 高准确率:在CSC测试集上生成结果纠错准确率高。
- 多功能性:不仅能进行中文拼写纠错,还带有句子润色和改写功能。
- 兼容性强:基于
pycorrector
项目,可支持ChatGLM原生模型和LoRA微调后的模型。
📦 安装指南
使用pycorrector
库
pip install -U pycorrector
使用HuggingFace Transformers
pip install transformers
💻 使用示例
基础用法
使用pycorrector
库调用模型进行纠错:
from pycorrector import GptCorrector
model = GptCorrector("THUDM/chatglm3-6b", "chatglm", peft_name="shibing624/chatglm3-6b-csc-chinese-lora")
r = model.correct_batch(["少先队员因该为老人让坐。"])
print(r) # ['少先队员应该为老人让座。']
高级用法
直接使用HuggingFace Transformers调用模型,可自定义更多参数:
import os
import torch
from peft import PeftModel
from transformers import AutoTokenizer, AutoModel
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True).half().cuda()
model = PeftModel.from_pretrained(model, "shibing624/chatglm3-6b-csc-chinese-lora")
sents = ['对下面文本纠错\n\n少先队员因该为老人让坐。',
'对下面文本纠错\n\n下个星期,我跟我朋唷打算去法国玩儿。']
def get_prompt(user_query):
vicuna_prompt = "A chat between a curious user and an artificial intelligence assistant. " \
"The assistant gives helpful, detailed, and polite answers to the user's questions. " \
"USER: {query} ASSISTANT:"
return vicuna_prompt.format(query=user_query)
for s in sents:
q = get_prompt(s)
input_ids = tokenizer(q).input_ids
generation_kwargs = dict(max_new_tokens=128, do_sample=True, temperature=0.8)
outputs = model.generate(input_ids=torch.as_tensor([input_ids]).to('cuda:0'), **generation_kwargs)
output_tensor = outputs[0][len(input_ids):]
response = tokenizer.decode(output_tensor, skip_special_tokens=True)
print(response)
📚 详细文档
模型评估
shibing624/chatglm3-6b-csc-chinese-lora
在CSC测试集上的表现如下:
输入文本 | 预测结果 |
---|---|
对下面文本纠错:少先队员因该为老人让坐。 | 少先队员应该为老人让座。 |
模型文件组成
chatglm3-6b-csc-chinese-lora
├── adapter_config.json
└── adapter_model.bin
训练参数
参数 | 详情 |
---|---|
num_epochs | 5 |
per_device_train_batch_size | 6 |
learning_rate | 2e-05 |
best steps | 25100 |
train_loss | 0.0834 |
lr_scheduler_type | linear |
base model | THUDM/chatglm3-6b |
warmup_steps | 50 |
save_strategy | steps |
save_steps | 500 |
save_total_limit | 10 |
bf16 | false |
fp16 | true |
optim | adamw_torch |
ddp_find_unused_parameters | false |
gradient_checkpointing | true |
max_seq_length | 512 |
max_length | 512 |
prompt_template_name | vicuna |
硬件及训练时长 | 6 * V100 32GB,训练48小时 |
训练数据集
- 中文拼写纠错数据集:https://huggingface.co/datasets/shibing624/CSC
- 中文语法纠错数据集:https://github.com/shibing624/pycorrector/tree/llm/examples/data/grammar
- 通用GPT4问答数据集:https://huggingface.co/datasets/shibing624/sharegpt_gpt4
如果需要训练文本纠错模型,请参考https://github.com/shibing624/pycorrector
🔧 技术细节
本模型基于THUDM/chatglm3-6b
进行LoRA微调,使用了特定的训练参数和数据集,在中文纠错任务上取得了较好的效果。通过LoRA微调,模型能够在不改变原模型结构的基础上,学习到中文纠错的特定知识。
📄 许可证
本项目采用apache-2.0
许可证。
📚 引用
@software{pycorrector,
author = {Ming Xu},
title = {pycorrector: Text Error Correction Tool},
year = {2023},
url = {https://github.com/shibing624/pycorrector},
}
Phi 2 GGUF
其他
Phi-2是微软开发的一个小型但强大的语言模型,具有27亿参数,专注于高效推理和高质量文本生成。
大型语言模型 支持多种语言
P
TheBloke
41.5M
205
Roberta Large
MIT
基于掩码语言建模目标预训练的大型英语语言模型,采用改进的BERT训练方法
大型语言模型 英语
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基础模型的蒸馏版本,在保持相近性能的同时更轻量高效,适用于序列分类、标记分类等自然语言处理任务。
大型语言模型 英语
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一个多语言大语言模型,针对多语言对话用例进行了优化,在常见的行业基准测试中表现优异。
大型语言模型 英语
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型 支持多种语言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基于Transformer架构的英语预训练模型,通过掩码语言建模目标在海量文本上训练,支持文本特征提取和下游任务微调
大型语言模型 英语
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI发布的开放预训练Transformer语言模型套件,参数量从1.25亿到1750亿,旨在对标GPT-3系列性能,同时促进大规模语言模型的开放研究。
大型语言模型 英语
O
facebook
6.3M
198
1
基于transformers库的预训练模型,适用于多种NLP任务
大型语言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多语言大语言模型系列,包含8B、70B和405B参数规模,支持8种语言和代码生成,优化了多语言对话场景。
大型语言模型
Transformers 支持多种语言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基础版是由Google开发的文本到文本转换Transformer模型,参数规模2.2亿,支持多语言NLP任务。
大型语言模型 支持多种语言
T
google-t5
5.4M
702
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98