MBZUAI/Bactrian-X
Viewer • Updated • 3.48M • 940 • 125
How to use feabries/TaiwanWordTranslator-v0.1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="feabries/TaiwanWordTranslator-v0.1")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("feabries/TaiwanWordTranslator-v0.1")
model = AutoModelForCausalLM.from_pretrained("feabries/TaiwanWordTranslator-v0.1")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use feabries/TaiwanWordTranslator-v0.1 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "feabries/TaiwanWordTranslator-v0.1"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "feabries/TaiwanWordTranslator-v0.1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/feabries/TaiwanWordTranslator-v0.1
How to use feabries/TaiwanWordTranslator-v0.1 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "feabries/TaiwanWordTranslator-v0.1" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "feabries/TaiwanWordTranslator-v0.1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "feabries/TaiwanWordTranslator-v0.1" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "feabries/TaiwanWordTranslator-v0.1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use feabries/TaiwanWordTranslator-v0.1 with Docker Model Runner:
docker model run hf.co/feabries/TaiwanWordTranslator-v0.1
https://github.com/SuJiaKuan/llm_tw_word
The model supports translation that converts text with China words to text with only Taiwan words. Example:
這個軟件的質量真高啊這個軟體的品質真高啊This model is fine-tuned from TinyLlama/TinyLlama-1.1B-Chat-v1.0 (by applying Instruction Finetuning). The dataset is collected from MBZUAI/Bactrian-X and automatically labeled by 繁化姬.
You can follow the example usage below, or see here to know how to integrate the model into a Python class.
import torch
from transformers import pipeline
SYSTEM_PROMPT = """\
對於輸入內容的中文文字,請將中國用語轉成台灣的用語,其他非中文文字或非中國用語都維持不變。
範例:
Input: ```這個視頻的質量真高啊```
Output: ```這個影片的品質真高啊```\
"""
text_trad = "這個軟件的質量真高啊"
pipeline = pipeline(
"text-generation",
model="feabries/TaiwanWordTranslator-v0.1",
torch_dtype=torch.bfloat16,
device_map="auto",
)
prompt = "Input: ```{}```".format(text_trad)
messages = [{
"role": "system",
"content": SYSTEM_PROMPT,
}, {
"role": "user",
"content": prompt,
}]
input_text = pipeline.tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
outputs = pipeline(
input_text,
do_sample=False,
max_new_tokens=2048,
)
print(outputs[0]["generated_text"])
# <|system|>
# 對於輸入內容的中文文字,請將中國用語轉成台灣的用語,其他非中文文字或非中國用語都維持不變。
#
# 範例:
# Input: ```這個視頻的質量真高啊```
# Output: ```這個影片的品質真高啊```</s>
# <|user|>
# Input: ```這個軟件的質量真高啊```</s>
# <|assistant|>
# Output: ```這個軟體的品質真高啊```
docker model run hf.co/feabries/TaiwanWordTranslator-v0.1