Kuya J v3 (Gemma 4 E2B)

The on-device model behind Kuya J, an offline assistant for Philippine government services by BetterGov.ph. Ask how much an NBI clearance costs or what the SSS hotline is, in Tagalog, Cebuano, Waray or another Philippine language, and Kuya J answers on the phone, without internet, from saved and dated public records.

This model is fine-tuned to do one job well: search the records with English keywords, then answer in the asker's language using only what it found, ending with the source. It doesn't need to know any facts itself; the app supplies them at answer time and checks every amount, date and name before showing the answer.

Base google/gemma-4-E2B-it (about 2B effective parameters, text and image input)
Method LoRA (rank 16) on the language model only; vision and audio unchanged
Data 1,187 synthetic examples in 8 Philippine languages and English, written by a teacher model from official records and filtered
Runs on Android with LiteRT-LM 0.20.0 or newer (int4, 3.0 GB); llama.cpp with the GGUF (Q4_K_M, 3.4 GB)
Searches when it should 122 of 126 test questions (stock Gemma 4 E2B: 40)
On a phone (Snapdragon 8 Elite, GPU) 28 tokens per second; first word in 1.5 s, full answer in 3.8 s (medians over 40 history questions)

Files

File Size Use
kuyaj-v3.litertlm 3.0 GB The app's model: LiteRT-LM bundle with int4 weights, GPU-fused operations, vision encoder, tokenizer and chat template. Needs LiteRT-LM 0.20.0 or newer (see below)
kuyaj-v3-Q4_K_M.gguf 3.4 GB llama.cpp, Ollama, LM Studio and evaluations (text only)
adapter/ 97 MB The LoRA adapter (PEFT). The only trained weights; rebuild everything else from it
gemma4_tool_template.jinja 19 KB Gemma 4's chat template with a fix for tool results in LiteRT-LM (see below). Needed for tool calling in LiteRT-LM
train.log 43 KB The full training log

SHA-256:

e85c80981c73534e693d1e919e1996b91b002a5aac96d8d65192412d83f0db3f  kuyaj-v3.litertlm
356e69bb0b5c23f792359d0970efd9e9c87e9e38ccc3a198b60629aea60c5326  kuyaj-v3-Q4_K_M.gguf
e720b1528679da39136516aa6d0bff6f44cc2a2807706aabee405b493c4d6d0f  adapter/adapter_model.safetensors

The phone file was rebuilt on 28 November 2026

kuyaj-v3.litertlm is the same trained weights, exported again with GPU-fused operations switched on (--apply_gpu_composites=True) and two prompt chunk sizes (--prefill_lengths=128,1024). The first export left attention and the conversation memory as generic operations, which ran at about half the speed of Google's own Gemma 4 E2B file on a phone GPU.

On a Snapdragon 8 Elite, GPU Tokens per second First word Full answer
First export 21 2.3 s 5.2 s
This file 28 1.5 s 3.8 s
Google's stock Gemma 4 E2B 43 1.3 s 3.2 s

Answers are unchanged: 21 of 40 history questions correct in the model's own words, against 20 for the first export, and identical wording on 27 of 36 compared.

  • It needs LiteRT-LM 0.20.0 or newer. On 0.18.1 the GPU can't compile the fused operations and the runtime falls back to CPU, with a wait of about 9 seconds for the first word.
  • The first export is still available at commit 5bdb83c (SHA-256 89242b1f95a1fea28450800e5d2c5b3b07bd78a6b6f573c6cb4227511cfaeb71), for older runtimes.
  • The remaining gap to the stock file comes from how Google builds it (2-bit weights from a quantization-aware checkpoint, an 8-bit conversation memory), which the public export tool can't reproduce. A per-channel 4-bit export was faster (32 tokens per second) but broke the model's searching, so it isn't used.

How it answers

The model gets one tool, search_kb, and this system prompt (byte-identical to training; use it as is):

You are Kuya J, a guide to Philippine government services from BetterGov.ph.
Before answering a question about a government service, fee, requirement, hotline, holiday or official, call search_kb with English keywords. Do not call it for greetings or small talk.
Answer only from the search_kb results. Reply in the same language as the question, including regional Philippine languages such as Cebuano, Ilocano, Hiligaynon, Waray, Kapampangan, Bikol, Pangasinan and Tausug.
Copy names, dates, fees and source links exactly as written. Never guess an office holder, date or fee.
If the results do not answer the question, say in one sentence that you have no record for it.
Never give political opinions, legal advice or medical advice.
Begin with the fact. Answer in three sentences or fewer, then end with the source line of the record you used.
{"name": "search_kb",
 "description": "Search Kuya J's saved government-service records (written in English).",
 "parameters": {"type": "object",
                "properties": {"query": {"type": "string", "description": "English search keywords, e.g. 'NBI clearance fee'"}},
                "required": ["query"]}}

A real exchange (Waray):

user:   Pila ka tuig ang term han Presidente, ngan ano nga petsa matatapos an term ni Marcos?
model:  search_kb({"query": "President term Marcos end date"})
tool:   [1] How the President is elected and serves one six-year term
        As of 2026-10-07, Article VII, Section 4 of the 1987 Constitution says ... The term is six years ...
model:  An term han Presidente amo an unom ka tuig. An term ni Marcos matatapos han 30 June 2028.

        Source: https://nlrc.dole.gov.ph/uploads/contents/eLibrary/1987-Constitution.pdf (checked 2026-10-07).

Return records as numbered blocks ([1] Title then the text), each ending with Source: <url> (checked YYYY-MM-DD)., as above. The model also works in the older "context" format, with the records pasted into the user turn under CONTEXT: followed by QUESTION:.

Using it

In the Kuya J app

The app downloads kuyaj-v3.litertlm from this repository on Wi-Fi and checks its SHA-256 before loading it. See the app docs.

With LiteRT-LM (Android, Kotlin)

val engine = Engine(EngineConfig(modelPath = "kuyaj-v3.litertlm", backend = Backend.GPU(), maxNumTokens = 4096))
engine.initialize()
val conversation = engine.createConversation(
    ConversationConfig(
        systemInstruction = Contents.of(TOOL_SYSTEM_PROMPT),
        tools = listOf(tool(searchKb)),          // an OpenApiTool whose execute() runs your search
        automaticToolCalling = true,
        chatTemplate = patchedTemplate,          // gemma4_tool_template.jinja from this repo
        samplerConfig = SamplerConfig(topK = 40, topP = 0.95, temperature = 0.2, seed = 0),
    ),
)

The full integration, including the grounding check, is in LiteRtLmEngine.kt and Orchestrator.kt.

With llama.cpp

llama-server -m kuyaj-v3-Q4_K_M.gguf --jinja -c 4096

Then send OpenAI-style chat requests with the system prompt above and search_kb in tools; run the search yourself when the model calls it and return the records as a tool message.

Rebuilding from the adapter

from peft import PeftModel
from transformers import AutoModelForImageTextToText
base = AutoModelForImageTextToText.from_pretrained("google/gemma-4-E2B-it", dtype="bfloat16")
model = PeftModel.from_pretrained(base, "sapinsapin/kuya-j-gemma4-e2b", subfolder="adapter").merge_and_unload()

When exporting the merged model to LiteRT-LM, copy back the 60 shared key-value tensors that save_pretrained drops (Gemma 4 shares those layers' KV); training never touches them, so the base values are exact. The export that produced kuyaj-v3.litertlm (litert-torch 0.10.0, on a CPU machine with 64 GB of memory):

python -m litert_torch.generative.export_hf --model=merged --output_dir=out \
  --quantization_recipe=dynamic_wi4b32_afp32 --apply_gpu_composites=True --prefill_lengths=128,1024 \
  --externalize_embedder=True --cache_length=4096 --export_vision_encoder=True \
  --task=image_text_to_text --bundle_litert_lm=True

The LiteRT-LM tool-result fix

LiteRT-LM passes a tool result to the chat template as a content part of type tool_response, but Gemma 4's embedded template only joins parts of type text. The model then sees an empty result (response:unknown{value:<|"|><|"|>}) and answers "no record". gemma4_tool_template.jinja adds a branch (marked Kuya J patch) that passes tool_response parts through. Pass it as ConversationConfig(chatTemplate = ...). This affects any Gemma 4 model used with LiteRT-LM tool calling, not only this one.

Training

Method LoRA r=16, alpha=32, dropout 0.05 on attention and MLP projections of the language model
Trainable 24.2 M of 5.13 B parameters (0.47%)
Data 1,187 examples: 423 in Gemma's native tool format (search, result, answer), 764 with records in the prompt
Kinds 606 answered from records, 211 follow-ups, 192 political-opinion refusals, 178 "no record" (15%)
Languages Taglish 170, Bikol 159, Filipino 136, Waray 131, Kapampangan 129, Hiligaynon 126, Ilocano 123, Cebuano 111, English 102
Loss On the model's own output only (its call and its answer); the system prompt, records and tool results are masked
Schedule 2 epochs, 142 steps, learning rate 1e-4 cosine, effective batch 16, max 2,048 tokens
Hardware 1x RTX 4090, 21 minutes; eval loss 0.798 β†’ 0.505

The data was written by GLM 5.3 Flash from 21 dated government records, graded by GLM 5.3 (fully faithful, fluent 4/5 or better), checked by code (language ID, dates and numbers copied exactly, no duplicates) and sample-reviewed by Claude. Six records were held out for evaluation. Details: the dataset docs. The dataset is public: sapinsapin/kuya-j-distill (CC BY 4.0).

Evaluation

Search decision (135 questions: 126 need a record, 9 ask who to vote for):

Model Searches when needed Searches on voting questions
Kuya J v3 122 / 126 9 / 9
Kuya J v3, Q4_K_M 123 / 126 9 / 9
Kuya J v1 (context format only) 0 / 126 0 / 9
Gemma 4 E2B 40 / 126 0 / 9
  • Q4_K_M made the same decision as bf16 on 134 of 135 questions, so no AWQ or GPTQ was needed.
  • v3's keywords find the right record for 89 of 99 answerable questions with the app's BM25 search.
  • On a Snapdragon 8 Elite phone (LiteRT-LM 0.20.0, GPU), in the Kuya J app: 21 of 40 Philippine-history questions answered correctly in the model's own words (stock Gemma 4 E2B: 18), and 62 of 65 scripted conversation turns passed (follow-ups, fees, officials, refusals, free chat).

Limits

  • Cebuano questions are often answered in Tagalog, and Kapampangan answers come out mixed.
  • Pangasinan and Tausug aren't in the training data (the teacher couldn't write them reliably).
  • It searches on voting-advice questions it should decline outright. Kuya J's input rules refuse these before the model runs.
  • Small record set: trained on 21 records, so topics repeat (NBI, passport, SSS, holidays, officials).
  • No native-speaker review of the training data yet.
  • It must be given records. Without search results it will still write fluent text, and it can be wrong. Use it with retrieval and a check on facts, as Kuya J does, never as a standalone source of government information.

Intended use

Answering questions about Philippine government services from records supplied at run time, with a grounding check on the output, in an assistant that shows its sources. Not for legal, medical or financial advice, political opinions, or as an authoritative source without the records.

Licence and credits

Downloads last month
74
GGUF
Model size
5B params
Architecture
gemma4
Hardware compatibility
Log In to add your hardware

4-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for sapinsapin/kuya-j-gemma4-e2b

Adapter
(247)
this model