Instructions to use hmkz-1981/gemma-4-e4b-translate-ml with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hmkz-1981/gemma-4-e4b-translate-ml with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="hmkz-1981/gemma-4-e4b-translate-ml") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("hmkz-1981/gemma-4-e4b-translate-ml") model = AutoModelForMultimodalLM.from_pretrained("hmkz-1981/gemma-4-e4b-translate-ml", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use hmkz-1981/gemma-4-e4b-translate-ml with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hmkz-1981/gemma-4-e4b-translate-ml" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "hmkz-1981/gemma-4-e4b-translate-ml", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/hmkz-1981/gemma-4-e4b-translate-ml
- SGLang
How to use hmkz-1981/gemma-4-e4b-translate-ml 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 "hmkz-1981/gemma-4-e4b-translate-ml" \ --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": "hmkz-1981/gemma-4-e4b-translate-ml", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "hmkz-1981/gemma-4-e4b-translate-ml" \ --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": "hmkz-1981/gemma-4-e4b-translate-ml", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use hmkz-1981/gemma-4-e4b-translate-ml with Docker Model Runner:
docker model run hf.co/hmkz-1981/gemma-4-e4b-translate-ml
gemma-4-e4b-translate-ml
Multilingual translation model built on Gemma 4 E4B. It covers Japanese, English, Chinese (Simplified and Traditional), Korean, French, German, Spanish, Portuguese, Italian and Russian: English ⇄ each language plus Japanese ⇄ Chinese and Japanese ⇄ Korean (24 directions trained).
Based on TranslateGemma. The training recipe, the prompt format and the evaluation protocol follow Google's TranslateGemma (TranslateGemma Technical Report, arXiv:2601.09012; released models such as google/translategemma-4b-it), re-implemented independently on Gemma 4. This is not an official TranslateGemma model.
Gemma 4 E4B をベースに、Google の TranslateGemma(技術報告 arXiv:2601.09012)の 手順・プロンプト形式・評価方法を参考にして、11言語(24方向)向けに独自に学習した翻訳モデルです(TranslateGemma の公式版ではありません)。
Prompt / プロンプト
Use the TranslateGemma prompt as the user message (thinking disabled), with the language names and codes
of the pair, e.g. English (en-US) to Traditional Chinese (zh-TW), Japanese (ja-JP) to Korean (ko-KR).
You are a professional English (en-US) to Traditional Chinese (zh-TW) translator. Your goal is to accurately convey the meaning and nuances of the original English text while adhering to Traditional Chinese grammar, vocabulary, and cultural sensitivities. Produce only the Traditional Chinese translation, without any additional explanations or commentary. Please translate the following English text into Traditional Chinese:
{text}
import torch
from transformers import AutoModelForCausalLM, AutoProcessor
model_id = "wahokun/gemma-4-e4b-translate-ml"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16, device_map="auto")
prompt = '''You are a professional English (en-US) to Traditional Chinese (zh-TW) translator. Your goal is to accurately convey the meaning and nuances of the original English text while adhering to Traditional Chinese grammar, vocabulary, and cultural sensitivities. Produce only the Traditional Chinese translation, without any additional explanations or commentary. Please translate the following English text into Traditional Chinese:
Please review the attached document by Friday.'''
text = processor.apply_chat_template([{"role": "user", "content": prompt}], tokenize=False,
add_generation_prompt=True, enable_thinking=False)
inputs = processor(text=text, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
print(processor.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Evaluation / 評価
Greedy decoding. Each cell is COMET-22 ↑ / MetricX-24 ↓, averaged over the directions of the group (X→Y = Japanese ⇄ Chinese / Korean). FLORES+ devtest sentences were not used for training or teacher selection.
| Test set | Directions | Gemma 4 E4B (base) | this model | ja⇄en-only SFT (phase 1) | TranslateGemma 4B |
|---|---|---|---|---|---|
| FLORES+ devtest | en→X (10) | 0.8952 / 1.925 | 0.8978 / 1.800 | 0.8967 / 1.808 | 0.8904 / 1.937 |
| FLORES+ devtest | X→en (10) | 0.8836 / 2.108 | 0.8836 / 2.059 | 0.8826 / 2.062 | 0.8760 / 2.113 |
| FLORES+ devtest | X→Y (4) | 0.8956 / 2.906 | 0.8953 / 2.872 | 0.8960 / 2.808 | 0.8895 / 3.063 |
| WMT24++ | en→X (10) | 0.8424 / 3.290 | 0.8488 / 3.069 | 0.8473 / 3.050 | 0.8386 / 3.107 |
Against the base model, paired bootstrap (95% CI) shows significant COMET-22 gains on most English→X directions; X→English and Japanese ⇄ Chinese/Korean are on par with the base model in COMET-22.
Training / 学習
- Teachers (chosen per direction on FLORES+ dev): Gemma 4 31B, DeepSeek V4.1 Flash, Qwen3.5-27B
- Per source: top-1 teacher greedy + sample, top-2 teacher greedy; the candidate with the best mean rank of MetricX-24 QE and COMET-22 MBR consensus was kept (plus language, script and length checks)
- Sources: MADLAD-400 (clean), 5,000 per direction; ja⇄en data from the phase-1 model; evaluation sets removed
- SFT data: 107,118 translation pairs + 18,108 general chat examples; general prompts from UltraChat, databricks-dolly-15k-ja and the Aya dataset, answered by Gemma 4 E4B
- LoRA r=32, alpha=32, text decoder attention/MLP only; embeddings and vision/audio towers frozen; loss on the reply only; 1 epoch
Limitations / 制限
- Directions outside the 24 trained ones fall back to the base model's ability.
- MetricX-24 improves more than COMET-22 on some directions; part of that is a bias from MetricX-based data selection.
License / ライセンス
The model weights are released under Apache 2.0, the license of the Gemma 4 base model. Data used for training (please also respect the terms of these sources):
| Source | Use | License / terms |
|---|---|---|
Gemma 4 E4B (google/gemma-4-E4B-it) |
base model | Apache 2.0 |
| MADLAD-400 (clean) | source sentences | ODC-BY 1.0 |
| Gemma 4 31B, Qwen3.5-27B | teacher translations | Apache 2.0 |
| DeepSeek V4.1 Flash (served by DeepSeek) | teacher translations | DeepSeek Open Platform terms (outputs may be used for model training) |
| UltraChat 200k | general-chat prompts | MIT |
| databricks-dolly-15k-ja | general-chat prompts (Japanese) | CC BY-SA 3.0 |
| Aya dataset | general-chat prompts (multilingual) | Apache 2.0 |
| FLORES+, WMT24++ | evaluation only (removed from training sources) | CC BY-SA 4.0 / Apache 2.0 |
This is an independent community model. It is not affiliated with or endorsed by Google, and it is not an official TranslateGemma release; "translategemma-recipe" refers to the published training method.
本モデルは個人による非公式のモデルで、Google とは関係ありません(TranslateGemma の公式版ではありません)。
Acknowledgements / 参考
- TranslateGemma Technical Report — https://arxiv.org/abs/2601.09012 (training recipe, prompt template, evaluation setup)
- Gemma 4 — base model
- MetricX-24 and COMET-22 — evaluation and data selection
- Downloads last month
- 10