Instructions to use shibing624/mengzi-t5-base-chinese-correction with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shibing624/mengzi-t5-base-chinese-correction with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shibing624/mengzi-t5-base-chinese-correction")# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("shibing624/mengzi-t5-base-chinese-correction") model = AutoModelForMultimodalLM.from_pretrained("shibing624/mengzi-t5-base-chinese-correction") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use shibing624/mengzi-t5-base-chinese-correction with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shibing624/mengzi-t5-base-chinese-correction" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibing624/mengzi-t5-base-chinese-correction", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/shibing624/mengzi-t5-base-chinese-correction
- SGLang
How to use shibing624/mengzi-t5-base-chinese-correction with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "shibing624/mengzi-t5-base-chinese-correction" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibing624/mengzi-t5-base-chinese-correction", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "shibing624/mengzi-t5-base-chinese-correction" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibing624/mengzi-t5-base-chinese-correction", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use shibing624/mengzi-t5-base-chinese-correction with Docker Model Runner:
docker model run hf.co/shibing624/mengzi-t5-base-chinese-correction
Use Docker images
docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "shibing624/mengzi-t5-base-chinese-correction" \
--host 0.0.0.0 \
--port 30000# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "shibing624/mengzi-t5-base-chinese-correction",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'YAML Metadata Warning:The pipeline tag "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other
T5 for Chinese Spelling Correction Model
中文拼写纠错模型
shibing624/mengzi-t5-base-chinese-correction evaluate SIGHAN2015 test data:
- Sentence Level: precision:0.8321, recall:0.6390, f1:0.7229
训练使用的数据集为下方提供的“SIGHAN+Wang271K中文纠错数据集”,在SIGHAN2015的测试集上达到接近SOTA水平。
未改动模型结构,finetune中文纠错数据集,评估纠错效果很好,模型潜力巨大。
Usage
本项目开源在中文文本纠错项目:pycorrector,可支持t5模型,通过如下命令调用:
pip install -U pycorrector
run:
from pycorrector.t5.t5_corrector import T5Corrector
nlp = T5Corrector("shibing624/mengzi-t5-base-chinese-correction").batch_t5_correct
i = "今天新情很好"
print(i, ' => ', nlp([i]))
output:
今天新情很好 => 今天心情很好 [('新', '心', 2, 3)]
模型文件组成:
mengzi-t5-base-chinese-correction
|-- config.json
|-- pytorch_model.bin
|-- special_tokens_map.json
|-- spiece.model
|-- tokenizer_config.json
`-- tokenizer.json
如果需要训练t5-correction,请参考https://github.com/shibing624/pycorrector/tree/master/pycorrector/t5
训练数据集
SIGHAN+Wang271K中文纠错数据集
| 数据集 | 语料 | 下载链接 | 压缩包大小 |
|---|---|---|---|
SIGHAN+Wang271K中文纠错数据集 |
SIGHAN+Wang271K(27万条) | 百度网盘(密码01b9) | 106M |
原始SIGHAN数据集 |
SIGHAN13 14 15 | 官方csc.html | 339K |
原始Wang271K数据集 |
Wang271K | Automatic-Corpus-Generation dimmywang提供 | 93M |
SIGHAN+Wang271K中文纠错数据集,数据格式:
[
{
"id": "B2-4029-3",
"original_text": "晚间会听到嗓音,白天的时候大家都不会太在意,但是在睡觉的时候这嗓音成为大家的恶梦。",
"wrong_ids": [
5,
31
],
"correct_text": "晚间会听到噪音,白天的时候大家都不会太在意,但是在睡觉的时候这噪音成为大家的恶梦。"
},
]
Citation
@software{pycorrector,
author = {Xu Ming},
title = {pycorrector: Text Error Correction Tool},
year = {2021},
url = {https://github.com/shibing624/pycorrector},
}
- Downloads last month
- 1,495
Install from pip and serve model
# Install SGLang from pip: pip install sglang# Start the SGLang server: python3 -m sglang.launch_server \ --model-path "shibing624/mengzi-t5-base-chinese-correction" \ --host 0.0.0.0 \ --port 30000# Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibing624/mengzi-t5-base-chinese-correction", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'