onkun: Gemma 4 12B IT tagger for kanji reading types (RS-LoRA, QAT base, merged)
Given a Japanese word, and optionally its reading, the model splits it into kanji and tags how each kanji is read:
| type | meaning | example |
|---|---|---|
on | Sino-Japanese reading (音読み) | 動画 どう・が |
kun | native Japanese reading (訓読み) | 春場所 はる・ば・しょ |
jukujikun | the word is read as a whole, not kanji by kanji (熟字訓) | 今日 きょう |
kana | kana in the word | |
other | in the label scheme, a reading found only in KANJIDIC2's name readings (nanori). That rule was off for training, so the model never saw this tag. |
Word patterns used in the results:
- pure on / pure kun: every kanji has that type.
- jūbako: two kanji, on + kun.
- yutō: two kanji, kun + on.
- mixed: three or more kanji with both on and kun.
- jukujikun: contains a jukujikun span.
Mixed words such as 重箱 (じゅう・ばこ, on + kun) and 湯桶 (ゆ・とう, kun + on) are handled kanji by kanji. Sound changes such as rendaku (場 → ば) and gemination are covered too.
This is a specialised tagger: use it with the prompt below. It is not meant as a general assistant (see Side effects).
What the evaluation does and does not show. Every label comes from dictionary lookups plus deterministic rules. Words the rules cannot settle are left out of training and of scoring:
- 11,105 pairs are quarantined (6,715 JMdict, 4,390 JMnedict): ambiguous or unmatched kanji, or multi-kanji spans the rules can't split;
- 6,561 JMdict pairs have no segmentation;
- 4,072 are out of scope.
The scores below therefore measure how well the model reproduces the dictionary rules on words the rules can label. They do not measure irregular words, unlisted readings or words outside the dictionaries, where a model would have to beat a lookup. No hand-labelled hard set exists yet.
Repository structure
- Root: the full merged weights (bf16 safetensors, for
transformers). Recommended. adapter/: the raw RS-LoRA adapter (PEFT).gguf/: merged GGUF files: f16, Q8_0, Q5_K_M, Q4_K_M and Q2_K. Q4_K_M is the evaluated release file.
Prompt format
The model was trained on exactly this system prompt, and it answers with one JSON object.
system: Tag the reading type of each kanji in the Japanese word: on, kun, jukujikun, kana or other. Answer with JSON {"segments": [{"text", "reading", "type"}]}.
user: Word: 春場所
Reading: はるばしょ
{"segments": [{"text": "春", "reading": "はる", "type": "kun"}, {"text": "場", "reading": "ば", "type": "kun"}, {"text": "所", "reading": "しょ", "type": "on"}]}
If you don't know the reading, write Word: 固有名詞 followed by The reading is not given: use the word's standard reading. (mode B). The model then supplies the reading too, which is less reliable (see Results).
Use greedy decoding (temperature 0) with thinking off. generation_config.json and the GGUF metadata (general.sampling.temp = 0) now default to greedy decoding; the first upload shipped Google's sampling defaults. All evaluation requests used temperature 0.
Usage
Merged model (Transformers)
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "julienp79/onkun-gemma-4-12b-it-rslora-qat"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
SYSTEM = ('Tag the reading type of each kanji in the Japanese word: on, kun, jukujikun, kana or other. '
'Answer with JSON {"segments": [{"text", "reading", "type"}]}.')
messages = [{"role": "system", "content": SYSTEM},
{"role": "user", "content": "Word: 今日\nReading: きょう"}]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
out = model.generate(inputs, max_new_tokens=256, do_sample=False)
print(tok.decode(out[0][inputs.shape[-1]:], skip_special_tokens=True))
GGUF (llama.cpp)
llama-server -hf julienp79/onkun-gemma-4-12b-it-rslora-qat:Q4_K_M --jinja -c 4096 --temp 0
# then POST to /v1/chat/completions with the system prompt above, temperature 0
Adapter (PEFT)
from peft import PeftModel
from transformers import AutoModelForCausalLM
base = AutoModelForCausalLM.from_pretrained("google/gemma-4-12B-it-qat-q4_0-unquantized",
device_map="auto", torch_dtype="auto")
model = PeftModel.from_pretrained(base, "julienp79/onkun-gemma-4-12b-it-rslora-qat", subfolder="adapter")
⚠️ rsLoRA and llama.cpp.
convert_lora_to_gguf.pyignoresuse_rslora, so llama.cpp scales the adapter by alpha/r = 1.0 and not by alpha/√r = 5.657. The adapter then runs at about 18% of its trained strength. Either pass--lora-scaled adapter.gguf:5.657, or (better) use the merged GGUFs ingguf/.Even at the correct scale, the adapter applied to the Q4_0 base behaved worse on general tasks than the merged model (see Side effects). Use the merged files.
Training
| Base | google/gemma-4-12B-it-qat-q4_0-unquantized |
| Method | QLoRA (4-bit fp4 base), RS-LoRA, SFT on the assistant turn only |
| LoRA | r = 32, alpha = 32 (use_rslora, scale 5.657), dropout 0, all attention and MLP projections of the language model |
| Data | 23,337 examples: 17,337 with the reading given (mode A) and 6,000 without it (mode B), from the train split only |
| Optimiser | AdamW 8-bit, lr 1e-4 with cosine decay, warmup 3%, effective batch 16, max length 640 tokens, 1 epoch (1,459 steps), seed 20261118 |
| Hardware | one RTX 3060 12 GB, 6.1 h, peak VRAM 10.9 GB |
| Merge | W' = W + 5.657 · (B @ A) in fp32, saved as bf16; GGUFs converted from the merged checkpoint |
Labels never come from an LLM. Every training and evaluation label is computed deterministically from dictionaries:
- JmdictFurigana gives the per-kanji segmentation of each (word, reading) pair from JMdict and JMnedict;
- each segment's kana is matched against the kanji's KANJIDIC2 on and kun readings, with explicit rules for sound changes (rendaku, gemination, ...);
- UniDic word origin is used as a cross-check.
Pairs the rules cannot settle (ambiguous, unmatched, or splittable multi-kanji spans) are quarantined and never used for training or scoring. The split is by written form (train / dev / test), so no evaluated written form was seen in training. Variant spellings of one JMdict entry (e.g. 綺麗 / 奇麗) are separate written forms and can fall on different sides of the split.
Results
Builds compared.
- The model is the release Q4_K_M (merged), unless a row says otherwise.
- The baseline is stock Gemma 4 12B QAT Q4_0, with its best non-thinking prompt (few-shot, step by step).
- Both use greedy decoding with thinking off.
- The other GGUF sizes (f16, Q8_0, Q5_K_M, Q2_K) were not evaluated. Q2_K in particular may be noticeably worse.
Δ is paired, with a 95% bootstrap CI. The test split was held out from every training and design decision, and it was evaluated twice. The first run served the adapter at the wrong scale (see the rsLoRA note); nothing was selected on either run.
Baseline caveats.
- With thinking on (capped at 1,024 tokens), the base model gains about 8 points on a harder 120-word dev sample. Thinking was not run on test, so the gap to a thinking base is smaller than shown.
- Part of the base's exact-match gap is formatting. On test, 1.5% of its answers fail to parse and 14.2% segment the word differently from the dictionary. The model has 0% and 0%.
Test split, 1,000 words, reading given (mode A)
| per-kanji type accuracy | whole-word exact match | |
|---|---|---|
| base Gemma 4 12B (best prompt) | 0.867 | 0.680 |
| this model | 0.982 | 0.966 |
| Δ | +11.4 [+9.6, +13.4] | +28.6 [+25.8, +31.5] |
By pattern (type accuracy, base → model):
| pattern | n | base | model | Δ [95% CI] |
|---|---|---|---|---|
| pure on | 491 | 0.928 | 0.995 | +6.7 [+4.7, +8.9] |
| pure kun | 310 | 0.873 | 0.968 | +9.5 [+6.2, +12.9] |
| mixed | 98 | 0.751 | 0.969 | +21.8 [+15.3, +28.5] |
| jukujikun | 34 | 0.467 | 0.957 | +48.9 [+34.1, +63.3] |
| jūbako (on + kun) | 36 | 0.833 | 0.944 | +11.1 [+0.0, +22.2] |
| yutō (kun + on) | 31 | 0.742 | 0.952 | +21.0 [+8.1, +35.5] |
The small pattern rows (31–36 words) have wide intervals.
Errors (test, mode A).
- Per-kanji confusion (gold → predicted): on → on 1,662, kun → kun 768, jukujikun → jukujikun 66. The main error is over-predicting jukujikun: 33 of the 47 kanji errors (on → jukujikun 16, kun → jukujikun 17), e.g. 括弧, 怪我, 紫蘇 and 矍鑠 tagged as whole-word readings.
- We read all 34 exact-match misses by hand. About 6 have debatable gold (二度 ふたたび, 三十路 みそじ, 枝折 しおり, 経糸 たていと, 白子 しらす, the kokuji 狆), and the rest are model errors.
- One answer garbled a katakana string into Cyrillic.
Test split, reading not given (mode B), n = 992. Any JMdict reading of the word is accepted, and the types are scored against the labels of the reading the model gave.
| base | model | |
|---|---|---|
| valid reading | 0.576 | 0.756 |
| type accuracy | 0.825 | 0.928 (+10.3 [+8.3, +12.3]) |
| whole-word exact match | 0.484 | 0.744 [0.715, 0.769] |
| type accuracy, where the reading is valid | 0.935 (n = 571) | 0.985 (n = 750) |
Most mode-B errors are wrong readings, not wrong types, so give the reading whenever you have it.
Dev split, 479 words: mode A 0.981 type, 0.967 EM. The unmerged adapter at the correct scale scores 0.987 and 0.975, a difference that is not significant.
Side effects (regression check vs the base model)
These rules were fixed before the run. Δ is model − base, where base is stock Q4_0. Two builds of this model were checked:
- the release Q4_K_M (merged);
- the PEFT adapter converted to GGUF at the correct scale and applied to Google's Q4_0 (
--lora).
| check | release Q4_K_M | adapter on Q4_0 | pre-registered limit |
|---|---|---|---|
| JCommonsenseQA, averaged over 5 rotations of the choices (1,119 questions) | +8.3 [+7.4, +9.1] pass | +8.3 [+7.4, +9.3] pass | lower bound > −3 |
| JA→EN translation, chrF (300 sentences) | −0.4 [−1.7, +0.7] fail (narrowly) | −2.2 [−3.8, −0.5] fail | lower bound > −1.5 |
| arithmetic (500 items) | −3.6 [−5.8, −1.6] fail | −1.4 [−3.6, +0.8] pass | lower bound > −5 |
| JSON leaking into general replies | 0 / 24 pass | 0 / 24 pass | ≤ 1 |
| reading a word in a sentence (dev words, base 86.3%) | 81.7% (−4.7 [−8.7, −0.7]) | 53.7% (−32.7) | none (no transfer claim) |
The adapter path keeps the QAT Q4_0 weights. It is slightly better on the tagging task (dev 0.987 vs 0.981, n.s.) and on arithmetic. But in the sentence-reading task it usually answers with the reading of the whole sentence, not of the asked word, and it loses more on translation.
The two builds may be two points on one trade-off between task strength and general ability. A sweep over the adapter scale has not been run.
General ability drifts a little:
- translation is roughly unchanged;
- arithmetic loses about 3.6 points;
- reading a word inside a sentence gets slightly worse.
JCommonsenseQA and position bias.
- The base model strongly favours option "3" and avoids "4": over 5,595 rotated prompts it picks them 1,628 and 582 times, against 1,119 expected for each.
- The fine-tuned model is close to uniform.
- Averaged over all rotations it gains +8.3 points, and it is right in all 5 rotations for 84% of questions, against 45% for the base.
Adapter-strength sweep (v2 adapter on Q4_0, effective scale s; dev mode A; Δ vs base):
| s | dev type acc | JA→EN chrF | arithmetic (500) | word in sentence | pre-registered rules |
|---|---|---|---|---|---|
| 1.0 | 0.931 | +0.9 | +0.6 | +1.7 | pass |
| 2.0 | 0.969 | +1.2 | −0.6 | 0.0 | pass |
| 3.0 | 0.976 | +0.5 | −0.2 | −2.0 (n.s.) | pass |
| 4.0 | 0.979 | −0.4 | −1.4 | −7.3 | translation fails |
| 5.657 (trained) | 0.987 | −2.2 | −1.4 | −32.7 | translation fails |
Task strength and general drift trade off smoothly along the scale. At s ≈ 3 the adapter keeps most of the task gain and passes every side-effect rule. For a general assistant that should also tag kanji, s = 3 is a reasonable setting: convert adapter/ with stock convert_lora_to_gguf.py, which gives scale 1.0, then load it with --lora-scaled adapter.gguf:3.0 on Google's Q4_0. s = 3 was chosen after seeing these numbers, so they are not an independent confirmation of it. The merged release files correspond to s = 5.657: treat them as a tagger.
Limitations
- The tags follow dictionary conventions (KANJIDIC2 reading lists, JmdictFurigana segmentation). Where those disagree with a linguist's analysis, the model follows the dictionaries.
- Names (JMnedict) and rare readings are the weakest areas. Multi-kanji spans that the rules can't split, and readings outside KANJIDIC2, were excluded, so the model has seen few of them.
- Mode B depends on the model knowing the reading, which it often does not.
Data licences and attribution
The labels and training data are derived from:
- KANJIDIC2, JMdict and JMnedict, © Electronic Dictionary Research and Development Group, CC BY-SA 4.0 (https://www.edrdg.org/edrdg/licence.html);
- JmdictFurigana / JmnedictFurigana (Doublevil), CC BY-SA 4.0 (https://github.com/Doublevil/JmdictFurigana);
- UniDic 3.1.0 (NINJAL), used only as a cross-check.
The evaluation also uses JCommonsenseQA (JGLUE, CC BY-SA 4.0) and Tatoeba sentences via jmdict-simplified (CC BY 2.0 FR). The model weights are subject to the Gemma terms of use.
Chat template
chat_template.jinja is the newer Gemma 4 template, the one the model was trained with. If your runtime ships an older Gemma template, use this one.