Spanish → Basque translation model for the
automotive and
energy domains,
fine-tuned from
HiTZ/Latxa-Llama-3.1-8B-Instruct.
A single set of LoRA adapters covers both domains. The domain is selected at
inference time through an Ámbito: line in the system prompt — this line is the
conditioning signal, and omitting or changing it loses most of the benefit of
domain fine-tuning.
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4MODEL = "jurgiraud/latxa-eseu-wmt26-augmented"
5
6tok = AutoTokenizer.from_pretrained(MODEL)
7model = AutoModelForCausalLM.from_pretrained(
8 MODEL, torch_dtype=torch.bfloat16, device_map="auto"
9)
10
11DOMAIN_PHRASE = {
12 "automotive": "el ámbito de la automoción",
13 "energy": "el ámbito de la energía",
14}
15DOMAIN_TAG = {"automotive": "automoción", "energy": "energía", "general": "general"}
16
17def system_prompt(domain):
18 if domain in DOMAIN_PHRASE:
19 opening = ("Eres un traductor experto del castellano al euskera (euskara batua), "
20 f"especializado en {DOMAIN_PHRASE[domain]}.")
21 registro = "y empleando la terminología asentada de ese ámbito. "
22 else:
23 opening = ("Eres un traductor experto del castellano al euskera (euskara batua), "
24 "capaz de trabajar con textos de cualquier ámbito.")
25 registro = "y empleando un registro estándar. "
26 return (
27 opening + "\n"
28 f"Ámbito: {DOMAIN_TAG[domain]}.\n"
29 "Traduce con precisión y naturalidad, respetando la declinación y la sintaxis "
30 "propias del euskera, " + registro +
31 "Conserva exactamente todas las cifras, unidades y nombres propios tal como "
32 "aparecen en el original, así como el formato del texto de partida (mayúsculas, "
33 "puntuación, saltos de línea y etiquetas). "
34 "No añadas explicaciones, comentarios ni el texto de partida. "
35 "Responde únicamente con la traducción."
36 )
37
38def translate(text, domain="automotive", max_new_tokens=512):
39 msgs = [{"role": "system", "content": system_prompt(domain)},
40 {"role": "user", "content": text.strip()}]
41 inputs = tok.apply_chat_template(
42 msgs, add_generation_prompt=True, return_tensors="pt"
43 ).to(model.device)
44 out = model.generate(
45 inputs,
46 max_new_tokens=max_new_tokens,
47 do_sample=False,
48 eos_token_id=tok.eos_token_id,
49 pad_token_id=tok.eos_token_id,
50 )
51 return tok.decode(out[0][inputs.shape[-1]:], skip_special_tokens=True).strip()
52
53print(translate(
54 "El motor de combustión interna alcanza su par máximo a 3.500 rpm.",
55 domain="automotive",
56))
Development sets are held out at the article level: 217 automotive, 252 energy,
300 general.
LoRA SFT with TRL on a single A100 40GB.
Final training loss 0.447; dev loss 0.436 automotive, 0.431 energy,
0.455 general
Held-out in-domain development sets, greedy decoding.
1@inproceedings{sainz-etal-2025-instructing,
2 title = {Instructing Large Language Models for Low-Resource Languages: A Systematic Study for Basque},
3 author = {Sainz, Oscar and Perez, Naiara and Etxaniz, Julen and Fernandez de Landa, Joseba
4 and Aldabe, Itziar and García-Ferrero, Iker and Zabala, Aimar and Azurmendi, Ekhi
5 and Rigau, German and Agirre, Eneko and Artetxe, Mikel and Soroa, Aitor},
6 booktitle = {Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing},
7 year = {2025},
8 pages = {29136--29160},
9 url = {https://aclanthology.org/2025.emnlp-main.1484/}
10}
11
12@inproceedings{etxaniz-etal-2024-latxa,
13 title = {Latxa: An Open Language Model and Evaluation Suite for Basque},
14 author = {Etxaniz, Julen and Sainz, Oscar and Perez, Naiara and Aldabe, Itziar and Rigau, German
15 and Agirre, Eneko and Ormazabal, Aitor and Artetxe, Mikel and Soroa, Aitor},
16 booktitle = {Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics},
17 year = {2024},
18 pages = {14952--14972},
19 url = {https://aclanthology.org/2024.acl-long.799/}
20}
Derived from Latxa, which is itself derived from Llama-3.1, so the
Llama 3.1 Community License
applies and its use restrictions carry over.