🚀 ChatGLM3-6B 日本語版 中国語スペル訂正LoRAモデル
このモデルは、ChatGLM3-6Bをベースにした中国語のスペル訂正LoRAモデルです。shibing624/chatglm3-6b-csc-chinese-lora
を使用することで、中国語の文章のスペルや文法の誤りを高精度に訂正することができます。また、文章の潤色や書き換えも可能です。
🚀 クイックスタート
✨ 主な機能
- 高精度な訂正:CSCテストデータでの評価結果から、高い訂正精度を示しています。
- 文章の潤色と書き換え:単なる訂正だけでなく、文章を自然に潤色し、書き換える機能も備えています。
- 柔軟な使用方法:
pycorrector
パッケージを通じて簡単に利用できるほか、HuggingFace Transformersを直接使用することも可能です。
📦 インストール
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)
出力結果:
少先队员应该为老人让座。
下个星期,我跟我朋友打算去法国玩儿。
📚 ドキュメント
モデルファイル構成
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を参照してください。
📄 ライセンス
このモデルはApache-2.0ライセンスの下で公開されています。
引用
@software{pycorrector,
author = {Ming Xu},
title = {pycorrector: Text Error Correction Tool},
year = {2023},
url = {https://github.com/shibing624/pycorrector},
}