This gemma3 model was trained 2x faster with
Unsloth and Huggingface's TRL library.
Fine-tuned
English → Kikuyu translation model based on Google's
TranslateGemma-12B-it.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_id = "gateremark/kikuyu_translategemma_12b_merged_V2"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11)
12
13def translate_to_kikuyu(text: str) -> str:
14 messages = [
15 {
16 "role": "user",
17 "content": [{
18 "type": "text",
19 "source_lang_code": "en",
20 "target_lang_code": "ki",
21 "text": text
22 }]
23 }
24 ]
25
26 input_ids = tokenizer.apply_chat_template(
27 messages,
28 tokenize=True,
29 add_generation_prompt=True,
30 return_tensors="pt"
31 ).to(model.device)
32
33 terminators = [
34 tokenizer.eos_token_id,
35 tokenizer.convert_tokens_to_ids("<end_of_turn>"),
36 ]
37
38 with torch.no_grad():
39 outputs = model.generate(
40 input_ids=input_ids,
41 max_new_tokens=256,
42 temperature=0.3,
43 do_sample=True,
44 eos_token_id=terminators,
45 )
46
47 response = tokenizer.decode(
48 outputs[0][input_ids.shape[1]:],
49 skip_special_tokens=True
50 )
51 return response.strip()
52
53# Example
54print(translate_to_kikuyu("Hello, how are you?"))
55# Output: Hihi, ũrĩ atĩa?
1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained(
4 model_name="gateremark/kikuyu_translategemma_12b_merged_V2",
5 max_seq_length=2048,
6 dtype=None,
7 load_in_4bit=True, # Optional: reduce VRAM to ~6GB
8)
1@misc{gatere2026kikuyutranslategemma,
2 author = {Mark Gatere},
3 title = {Kikuyu TranslateGemma-12B: Fine-tuning TranslateGemma for Low-Resource Bantu Language Translation},
4 year = {2026},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/gateremark/kikuyu_translategemma_12b_merged_V2}}
7}