Instructions to use NbAiLab/nordlyd-translate-gemma4B-nov26preview with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NbAiLab/nordlyd-translate-gemma4B-nov26preview with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "translation" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("translation", model="NbAiLab/nordlyd-translate-gemma4B-nov26preview")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("NbAiLab/nordlyd-translate-gemma4B-nov26preview") model = AutoModelForMultimodalLM.from_pretrained("NbAiLab/nordlyd-translate-gemma4B-nov26preview", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Nordlyd Translate Gemma 4B · November 2026 preview
Nordlyd Translate Gemma 4B · November 2026 preview
Nordlyd is a family of speech and language models developed by the National Library of Norway. This 4B text translation model supports all translation directions among Danish, English, Norwegian Bokmål, and Swedish, plus translation between Bokmål and Nynorsk. It is based on Google's TranslateGemma-4B-IT, with supervised fine-tuning followed by reinforcement learning.
Preview release: evaluate the model on your own texts before relying on its translations. It can omit content, alter names or numbers, and choose wording that differs from your intended meaning.
Contents
- Model at a glance
- Supported translation directions
- Quick start: translate a sentence
- Bokmål and Nynorsk
- Prompt format
- Long texts and troubleshooting
- Evaluation
- Training and provenance
- Local download
- Limitations and responsible use
- License, feedback, and acknowledgements
Model at a glance
| Item | Details |
|---|---|
| Developer | National Library of Norway |
| Model | nordlyd-translate-gemma4B-nov26preview |
| Base model | google/translategemma-4b-it |
| Model size | 4B |
| Task | Text translation, including Bokmål ↔ Nynorsk |
| Translation directions | 14; see supported directions |
| Inference | Hugging Face Transformers |
| Example hardware | CUDA GPU with bfloat16 support; see setup |
| Access | Public download; no access approval required |
| Terms | Gemma Terms of Use |
Supported translation directions
| Source | Supported targets |
|---|---|
| Danish | English, Norwegian Bokmål, Swedish |
| English | Danish, Norwegian Bokmål, Swedish |
| Norwegian Bokmål | Danish, English, Swedish, Norwegian Nynorsk |
| Swedish | Danish, English, Norwegian Bokmål |
| Norwegian Nynorsk | Norwegian Bokmål |
These are 14 directed translation tasks, not 14 languages. Nynorsk ↔ English, Danish, or Swedish is not included in this release's training and evaluation coverage.
Use the following language codes with the examples below:
| Language or written standard | Code |
|---|---|
| Danish | da |
| English | en |
| Norwegian Bokmål | no |
| Norwegian Nynorsk | nn |
| Swedish | sv |
Use no for Bokmål to follow the Norwegian prompt naming in the earlier model's usage example. These are the translation template's language codes; the nob, nno, and eng arguments used by the Nordlyd ASR helper are a separate interface.
Quick start: translate a sentence
1. Prepare your environment
The example uses a CUDA-capable NVIDIA GPU with bfloat16 support and a compatible PyTorch installation. Install PyTorch using its installation guide, then create or activate an isolated Python environment for the remaining dependencies.
For example, with Python 3.12:
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
# Install the appropriate PyTorch build in this environment first.
python -m pip install "transformers>=5.6.1" accelerate sentencepiece pillow huggingface_hub
The checkpoint was exported with Transformers 5.6.1; the installation command uses that as its starting version. A minimum GPU memory requirement and CPU or Apple Silicon performance have not been established for this preview.
Check that PyTorch can see the GPU:
python -c "import torch; print('CUDA available:', torch.cuda.is_available())"
Expected result: CUDA available: True for the GPU workflow shown here.
2. Model download
The model and processor files are publicly downloadable from Hugging Face. No access approval or login is required. The Python example below downloads and caches them automatically on first use; you do not need to clone the repository. See local download if you prefer to download the files in advance.
3. Translate Danish into Bokmål
Save this as translate_example.py and run python translate_example.py. The translate function reuses the loaded model, so you can call it for several texts without reloading the weights.
import torch
from transformers import AutoProcessor, AutoModelForImageTextToText
MODEL_ID = "NbAiLab/nordlyd-translate-gemma4B-nov26preview"
processor = AutoProcessor.from_pretrained(MODEL_ID)
model = AutoModelForImageTextToText.from_pretrained(
MODEL_ID,
dtype=torch.bfloat16,
device_map="auto",
)
model.eval()
def translate(text, source_lang, target_lang):
messages = [{
"role": "user",
"content": [{
"type": "text",
"source_lang_code": source_lang,
"target_lang_code": target_lang,
"text": text,
}],
}]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
input_length = inputs["input_ids"].shape[-1]
with torch.inference_mode():
generated = model.generate(
**inputs,
max_new_tokens=512,
do_sample=False,
)
return processor.decode(
generated[0][input_length:],
skip_special_tokens=True,
).strip()
print(translate(
"Jordskælv og tsunami raserer ø i Indonesien.",
source_lang="da",
target_lang="no",
))
Expected result: a Bokmål translation printed as plain text, without the prompt or additional commentary. A possible translation is:
Jordskjelv og tsunami raserer øy i Indonesia.
The first run also downloads and loads the model, so it takes longer than subsequent runs. Review the result against the source; greedy decoding (do_sample=False) does not guarantee accuracy.
Bokmål, Nynorsk, and NormForm
For Bokmål → Nynorsk, change the source and target codes. Add this call to the script above:
print(translate(
"Vi skal være hjemme og sette oss ned for å lese.",
source_lang="no",
target_lang="nn",
))
For the reverse direction, use source_lang="nn" and target_lang="no".
Prompt format
Use the repository's processor and bundled chat template. For text translation, provide a user message with exactly one content item:
| Field | Value |
|---|---|
role |
"user" |
type |
"text" |
source_lang_code |
Source language code, such as "da" |
target_lang_code |
Target language code, such as "no" |
text |
Only the source text to translate |
The template builds the translation instruction and language names for you. Do not put a complete translation instruction inside text, or omit the language-code fields. Call apply_chat_template(..., add_generation_prompt=True) and decode only the newly generated tokens, as in the quick start.
TranslateGemma uses an image-text model class and processor, which is why the example loads AutoModelForImageTextToText. This card documents text translation; inherited image-processing components do not establish evaluated image-translation capability for this fine-tuned checkpoint.
The bundled template contains more language names than this release's 14 supported directions. A code being accepted by the template does not establish training or evaluation coverage for that pair. See the base model card for upstream template documentation.
Long texts and troubleshooting
Translate sentences or manageable paragraphs rather than entire documents. The earlier model's recipe used a 512-token completion limit; the quick start retains that budget. The new checkpoint's card does not establish a validated maximum document length.
| Symptom | What to check |
|---|---|
| Model download fails | Check your network connection and the repository ID. |
| Model class or configuration is not recognised | Check the installed Transformers version against the checkpoint's exported version (5.6.1). |
| Missing language-code error | Include source_lang_code and target_lang_code in the single text content item. |
| The prompt appears in the output | Decode tokens after the input length, rather than the full generated sequence. |
| The translation stops early | Check whether generation exhausted max_new_tokens; treat the result as potentially incomplete. Split the source into shorter units. |
| Repetition, omissions, or changed numbers | Compare with the source and try shorter, coherent excerpts. The training rewards do not guarantee error-free output. |
| GPU runs out of memory | Shorten the input, reduce batch size if your application batches requests, and check device placement. |
Increasing the output budget is not a substitute for checking a translation. When splitting documents, preserve paragraph order and review names, terminology, and context across segment boundaries.
Evaluation
The following are the new checkpoint's reported scores, using full test sets and greedy decoding. BLEU measures overlap with reference wording; chrF measures character-level overlap. Higher is better for both, but neither establishes that an individual translation is correct.
| Evaluation set | BLEU | chrF |
|---|---|---|
| FLORES+ devtest · 12 directions | 45.82 | 69.44 |
| NTREX · 12 directions | 36.66 | 62.53 |
| National Library of Norway gold dev · 12 directions | 68.86 | 85.10 |
| NPK/NDLA test | 87.28 | 94.52 |
The new checkpoint's card does not report human evaluation. Automatic evaluation leaves terminology, register, semantic errors, and domain-specific behaviour to be assessed for the intended use.
Training and provenance
The model starts from google/translategemma-4b-it and uses two training stages:
| Stage | Reported settings |
|---|---|
| Supervised fine-tuning (SFT) | Learning rate 8e-6, batch size 128, bfloat16. The checkpoint used to start GRPO was step 70,000, epoch 1.91. |
| Group Relative Policy Optimization (GRPO) | 20,000 steps using TRL and vLLM; learning rate 2e-6, cosine schedule, 500 warmup steps, 6 generations per prompt. |
The Bokmål ↔ Nynorsk portion contains 807,164 parallel pairs from the CC0 NPK/NDLA dataset, used in both directions. Both sides of each retained pair are CC0-licensed. The remaining language pairs use the National Library of Norway's gold parallel corpus, as in the earlier iteration.
GRPO uses 49,152 gold prompts plus 4,096 CC0 prompts for each Bokmål–Nynorsk direction. Its reward components are:
| Reward | Weight |
|---|---|
| Chunked xCOMET-XL | 1.0 |
| chrF | 0.5 |
| Repetition | 0.2 |
| Numeric stability | 0.2 |
The CC0 restriction describes the Bokmål–Nynorsk training subset. It does not mean that all training data or the model weights are CC0.
Local download
To download the model and processor for local loading:
hf download NbAiLab/nordlyd-translate-gemma4B-nov26preview \
--local-dir ./nordlyd-translate-gemma4B-nov26preview
Then set MODEL_ID = "./nordlyd-translate-gemma4B-nov26preview" in the quick start. For repeatable experiments, record the model revision and package versions; use --revision COMMIT to download a specific snapshot.
Limitations and responsible use
- Meaning and factual details: translations can omit or add material, change names or numbers, or alter tone. Check important content against the source.
- Language coverage: Nynorsk is covered through Bokmål ↔ Nynorsk. Direct Nynorsk translation with English, Danish, or Swedish is outside the reported coverage.
- Domain variation: reported general-domain scores are lower than the gold development-set scores. Evaluate your domain rather than assuming the highest score applies to it.
- Long documents: segment longer texts and check consistency across excerpts. A large inherited context window does not establish validated document-level translation quality.
- Task scope: this is a translation model. General conversation, instruction following, and image translation are not evaluated by this card.
Handle source texts and translations according to your organisation's privacy and data-handling requirements. Use human review where translation errors could affect people.
License, feedback, and acknowledgements
This model is derived from TranslateGemma and is subject to the Gemma Terms of Use. The CC0 status of the Bokmål–Nynorsk training pairs is separate from the terms governing the model.
Report reproducible issues through this repository's Community tab. Include the model revision, package versions, language direction, generation settings, source text, and unexpected output. Share text only when you have permission to do so. For issues that cannot be described publicly, email ai-lab@nb.no.
When referring to this preview, use Nordlyd Translate Gemma 4B — November 2026 preview, National Library of Norway, together with the repository and revision used.
Nordlyd is a research project at the National Library of Norway. The National Library of Norway retains full ownership of the models and associated research outputs. Research contributions were made by Phoebe Parsons, Freddy Wetjen, Thea Tollersud, and Per Egil Kummervold, who take responsibility for any remaining errors and shortcomings.
We would like to acknowledge Sigma2 for providing computational and storage resources on the Olivia/LUMI HPC system under project NN30001K.
The model builds on Google's TranslateGemma. Training uses Hugging Face TRL for GRPO and Unbabel XCOMET-XL as a reward model.
- Downloads last month
- 26
Model tree for NbAiLab/nordlyd-translate-gemma4B-nov26preview
Base model
google/translategemma-4b-it