p208p2002/zhtw-sentence-error-correction
Viewer • Updated • 600k • 85 • 5
How to use p208p2002/bloom-1b1-zh-error-correction-dpo with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="p208p2002/bloom-1b1-zh-error-correction-dpo") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("p208p2002/bloom-1b1-zh-error-correction-dpo")
model = AutoModelForCausalLM.from_pretrained("p208p2002/bloom-1b1-zh-error-correction-dpo")How to use p208p2002/bloom-1b1-zh-error-correction-dpo with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "p208p2002/bloom-1b1-zh-error-correction-dpo"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "p208p2002/bloom-1b1-zh-error-correction-dpo",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/p208p2002/bloom-1b1-zh-error-correction-dpo
How to use p208p2002/bloom-1b1-zh-error-correction-dpo with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "p208p2002/bloom-1b1-zh-error-correction-dpo" \
--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": "p208p2002/bloom-1b1-zh-error-correction-dpo",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "p208p2002/bloom-1b1-zh-error-correction-dpo" \
--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": "p208p2002/bloom-1b1-zh-error-correction-dpo",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use p208p2002/bloom-1b1-zh-error-correction-dpo with Docker Model Runner:
docker model run hf.co/p208p2002/bloom-1b1-zh-error-correction-dpo
使用DPO訓練的中文糾錯模型。
from transformers import AutoTokenizer, AutoModelForCausalLM, LlamaForCausalLM,AddedToken
import sys
mode_id = "p208p2002/bloom-1b1-zh-error-correction-dpo"
model: LlamaForCausalLM = AutoModelForCausalLM.from_pretrained("p208p2002/bloom-1b1-zh-error-correction-dpo")
tokenizer = AutoTokenizer.from_pretrained("p208p2002/bloom-1b1-zh-error-correction-dpo")
test_texts = [
"為了潔約能源請隨守關閉沒有使用的電器",
"今天新情很好",
"你快樂我也很高心",
"但不再算再找實習生了",
"今天太陽很大要注意篩傷",
"你要不要和我依起去台北",
"清晨六點終太陽會升起",
"傾城六點鐘太陽會升起",
"鍋馬路時你應該要注意虹綠燈",
"他正在學學彈吉他",
"下樓梯請注意階梯",
"此信件為系統自動發送之通知",
"此信件為系統自動發送知通知",
"如為誤傳也請立即刪除本郵件並通知寄件者"
]
for text in test_texts:
inputs = tokenizer(
f"{tokenizer.bos_token}{text} {tokenizer.eos_token}\n {tokenizer.bos_token}",
return_tensors="pt",
add_special_tokens=False
)["input_ids"]
out = model.generate(
inputs,
max_new_tokens=20,
)
decode_out = tokenizer.decode(out[0])
input_text,output_text = decode_out.split("\n")
input_text = input_text.strip()
output_text = output_text.strip()
print("input :",input_text)
print("output:",output_text)
print('-'*30)
input: <s>為了潔約能源請隨守關閉沒有使用的電器 </s>
output: <s>為了節約能源請隨時關閉沒有使用的電器 </s>
------------------------------
input: <s>今天新情很好 </s>
output: <s>今天心情很好 </s>
------------------------------
input: <s>你快樂我也很高心 </s>
output: <s>你快樂我也很高興 </s>
------------------------------
input: <s>但不再算再找實習生了 </s>
output: <s>但不再去找實習生了 </s>
------------------------------
input: <s>今天太陽很大要注意篩傷 </s>
output: <s>今天太陽很大要注意一下 </s>
------------------------------
input: <s>你要不要和我依起去台北 </s>
output: <s>你要不要和我一起去台北 </s>
------------------------------
input: <s>清晨六點終太陽會升起 </s>
output: <s>清晨六點鐘太陽會升起 </s>
------------------------------
input: <s>傾城六點鐘太陽會升起 </s>
output: <s>凌晨六點鐘太陽會升起 </s>
------------------------------
input: <s>鍋馬路時你應該要注意虹綠燈 </s>
output: <s>過馬路時你應該要注意紅綠燈 </s>
------------------------------
input: <s>他正在學學彈吉他 </s>
output: <s>他正在學習彈吉他 </s>
------------------------------
input: <s>下樓梯請注意階梯 </s>
output: <s>下樓梯請注意階梯 </s>
------------------------------
input: <s>此信件為系統自動發送之通知 </s>
output: <s>此信件為系統自動發送之通知 </s>
------------------------------
input: <s>此信件為系統自動發送知通知 </s>
output: <s>此信件為系統自動發送通知 </s>
------------------------------
input: <s>如為誤傳也請立即刪除本郵件並通知寄件者 </s>
output: <s>如為誤傳也請立即刪除本郵件並通知寄件者 </s>
------------------------------
input : <s>為了潔約能源請隨守關閉沒有使用的電器 </s>
output: <s>為了節約能源請隨時關閉沒有使用的電器 </s>
------------------------------
input : <s>今天新情很好 </s>
output: <s>今天心情很好 </s>
------------------------------
input : <s>你快樂我也很高心 </s>
output: <s>你快樂我也很高興 </s>
------------------------------
input : <s>但不再算再找實習生了 </s>
output: <s>但不再去找實習生了 </s>
------------------------------
input : <s>今天太陽很大要注意篩傷 </s>
output: <s>今天太陽很大要注意一下 </s>
------------------------------
input : <s>你要不要和我依起去台北 </s>
output: <s>你要不要和我一起去台北 </s>
------------------------------
input : <s>清晨六點終太陽會升起 </s>
output: <s>清晨六點鐘太陽會升起 </s>
------------------------------
input : <s>傾城六點鐘太陽會升起 </s>
output: <s>凌晨六點鐘太陽會升起 </s>
------------------------------
input : <s>鍋馬路時你應該要注意虹綠燈 </s>
output: <s>過馬路時你應該要注意紅綠燈 </s>
------------------------------
input : <s>他正在學學彈吉他 </s>
output: <s>他正在學習彈吉他 </s>
------------------------------
input : <s>下樓梯請注意階梯 </s>
output: <s>下樓梯請注意階梯 </s>
------------------------------
input : <s>此信件為系統自動發送之通知 </s>
output: <s>此信件為系統自動發送之通知 </s>
------------------------------
input : <s>此信件為系統自動發送知通知 </s>
output: <s>此信件為系統自動發送通知 </s>
------------------------------
input : <s>如為誤傳也請立即刪除本郵件並通知寄件者 </s>
output: <s>如為誤傳也請立即刪除本郵件並通知寄件者 </s>
------------------------------