Instructions to use google/translategemma-4b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/translategemma-4b-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/translategemma-4b-it") 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)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("google/translategemma-4b-it") model = AutoModelForImageTextToText.from_pretrained("google/translategemma-4b-it") 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use google/translategemma-4b-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/translategemma-4b-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/translategemma-4b-it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/google/translategemma-4b-it
- SGLang
How to use google/translategemma-4b-it 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 "google/translategemma-4b-it" \ --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": "google/translategemma-4b-it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "google/translategemma-4b-it" \ --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": "google/translategemma-4b-it", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use google/translategemma-4b-it with Docker Model Runner:
docker model run hf.co/google/translategemma-4b-it
TranslateGemma Terminology Control and Context Support for Scientific Translation
Hi, I am currently using TranslateGemma for scientific / medical paper translation and would like to understand whether the model supports terminology control and document-level context beyond basic prompting.
I have several questions:
- Hotword / Forced Terminology Support
Does TranslateGemma support any built-in mechanism similar to hotwords (like Whisper), forced terminology, keyword biasing, or lexicon constraints during generation?
For example, can I prioritize preferred translations such as:
- sarcopenia -> 근감소증
- muscle fat infiltration -> 근육 지방 침윤
- lean muscle volume -> 제지방 근육 부피
- Context / Reference Text Injection
Is there any supported parameter or recommended input format for providing additional context during translation?
Examples:
- paper abstract
- domain background
- previous paragraph
- document summary
- glossary
I would like the model to use context for disambiguation and terminology consistency.
- Generation Parameters Beyond Prompting
Besides prompt engineering, are there Hugging Face Transformers generation parameters that can help terminology consistency or contextual translation?
Examples:
- forced tokens
- forced decoder ids
- prefix constraints
- prefix_allowed_tokens_fn
- logits_processor
- bad_words_ids
- constrained decoding
- custom token biasing
- Multi-turn / Memory / Document Translation
For translating long scientific documents, what is the best practice for preserving context across multiple sentences or paragraphs?
Should previous translated segments or previous source paragraphs be included in the prompt?
Does TranslateGemma support document-level translation behavior, or is sentence-by-sentence prompting recommended?
- Recommended Best Practice for Scientific Translation
For domains like medicine, biology, and clinical research, what is the recommended method to improve:
- terminology consistency
- abbreviation handling
- paragraph coherence
- accurate technical translation
If possible, could you also share a Hugging Face Transformers implementation example for these use cases?
Thank you.
Hi @EliasKim Apologies for late response
Thanks for the detailed questions. Let me go through each one
Hotword / Forced Terminology Support
TranslateGemma does not include a built-in hotword or lexical constraint mechanism. It has no equivalent to Whisper's hotwords parameter, and forced_decoder_ids does not apply here . The supported and recommended path for terminology control is prompt-level injection via the text field.Context / Reference Text Injection
There is no dedicated context parameter in the chat template. The text property in the content list entry is designed to contain the text to translate. TranslateGemma may respond well to other prompting techniques to support use cases that go beyond the provided chat template, such as Automatic Translation Post-Editing. These should be crafted manually using the special control tokens and structures specified in the Gemma 3 Technical Report, and sent directly to the tokenizer instead of using apply_chat_template().Multi-turn / Memory / Document Translation
TranslateGemma has no cross-call memory or document state. Each call is stateless. My recommendation would be to translate paragraph by paragraph .Recommended Best Practice for Scientific Translation
Please use apply_chat_template() with do_sample=False . Deterministic decoding directly helps terminology consistency since the model produces the same output for the same input. Always chunk your medical papers into paragraphs well under the 2K token limit.
Thanks