English_to_Japanese Translator
Collection
LLMを用いた英日翻訳モデル • 2 items • Updated • 1
How to use ryota39/Tora_4B with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="ryota39/Tora_4B") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("ryota39/Tora_4B")
model = AutoModelForCausalLM.from_pretrained("ryota39/Tora_4B")How to use ryota39/Tora_4B with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "ryota39/Tora_4B"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "ryota39/Tora_4B",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/ryota39/Tora_4B
How to use ryota39/Tora_4B with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "ryota39/Tora_4B" \
--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": "ryota39/Tora_4B",
"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 "ryota39/Tora_4B" \
--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": "ryota39/Tora_4B",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use ryota39/Tora_4B with Docker Model Runner:
docker model run hf.co/ryota39/Tora_4B
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("rinna/bilingual-gpt-neox-4b-instruction-sft", use_fast=False)
model = AutoModelForCausalLM.from_pretrained("ryota39/Tora_4B")
if torch.cuda.is_available():
model = model.to("cuda")
prompt = list()
prompt.append("指示: 以下の英語を日本語に翻訳してください。")
prompt.append("ユーザー: He delivers a presentation under the title of Stress levels estimation from facial video based on non-contact measurement of pulse wave.")
prompt.append("システム: ")
prompt = '\n'.join(prompt)
print(prompt)
token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
with torch.no_grad():
output_ids = model.generate(
token_ids.to(model.device),
max_new_tokens=512,
do_sample=False,
temperature=0.7,
top_p=0.85,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id
)
output = tokenizer.decode(output_ids.tolist()[0][token_ids.size(1):])
print(output)
# 彼は、顔のビデオから心拍数と心拍間隔を推定する方法について話した。