ใ‚ใชใŸใฏไฝ•ใ•ใ‚Œใฆใ‚‹ๆ–น๏ผŸ

ใƒใƒณใƒ‰ใ€Žไธ€ๅฎถDumb Rock!ใ€ใฎ้ ˆ่ณ€ ่•พๅถ๏ผˆใ™ใŒ ใ‚‰ใ„ใ‹๏ผ‰ ใฎๅฃ่ชฟใƒปไบบๆ ผใ‚’ๅ†็พใ™ใ‚‹LoRAใ‚ขใƒ€ใƒ—ใ‚ฟใƒผใงใ™ใ€‚ unsloth/gemma-4-E4B-it ใฎไธŠใงใƒ•ใ‚กใ‚คใƒณใƒใƒฅใƒผใƒ‹ใƒณใ‚ฐใ•ใ‚Œใฆใ„ใพใ™ใ€‚

ๆณจๆ„๏ผˆ็ด ใฎใพใพใ ใจใกใ‚ƒใ‚“ใจๅ–‹ใ‚Šใพใ›ใ‚“๏ผ‰

  1. thinking๏ผˆๆ€่€ƒใƒขใƒผใƒ‰๏ผ‰ใฏๅฟ…ใšใ‚ชใƒ•ใซใ—ใฆใใ ใ•ใ„
    • ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆใฎใพใพๅ‹•ใ‹ใ™ใจใ€ๆ€่€ƒ้Ž็จ‹ใฎ็กฌใ„ไบบๆ ผใซไธŠๆ›ธใใ•ใ‚Œใฆใ‚ญใƒฃใƒฉใŒๅดฉๅฃŠใ—ใพใ™ใ€‚
    • Transformers / Unsloth ใชใ‚‰ enable_thinking=Falseใ€llama.cpp ใชใ‚‰ --reasoning off ใ‚’ๆŒ‡ๅฎšใ—ใฆใใ ใ•ใ„ใ€‚
  2. ใ‚ทใ‚นใƒ†ใƒ ใƒ—ใƒญใƒณใƒ—ใƒˆใ‚’ๅฟ…ใšๅ…ฅใ‚Œใฆใใ ใ•ใ„
    • ็›ธๆ‰‹ใจใฎ้–ขไฟ‚ๆ€งใซใ‚ˆใ‚‹ๅฃ่ชฟใฎๅˆ‡ใ‚Šๆ›ฟใˆ๏ผˆไปฒ้–“ใธใฎๅ…ƒๆฐ—ใชใ‚ฟใƒกๅฃ๏ผ็›ฎไธŠใ‚„ใ‚ˆใ่€…ใธใฎๅดฉใ‚ŒใŸๆ•ฌ่ชž๏ผ‰ใ‚’ใ‚ทใ‚นใƒ†ใƒ ใƒ—ใƒญใƒณใƒ—ใƒˆๅ‰ๆใงๅญฆ็ฟ’ใ—ใฆใ„ใพใ™ใ€‚็„กใ—ใง่ฉฑใ—ใ‹ใ‘ใ‚‹ใจ็ด ใฎใƒขใƒ‡ใƒซใฃใฝใใชใ‚Šใพใ™ใ€‚
  3. Repeat Penalty๏ผˆ็นฐใ‚Š่ฟ”ใ—ใƒšใƒŠใƒซใƒ†ใ‚ฃ๏ผ‰ใ‚’ไธŠใ’ใ™ใŽใชใ„ใงใใ ใ•ใ„
    • 1.15 ไปฅไธŠใซใ™ใ‚‹ใจใ€่•พๅถใ‚‰ใ—ใ„ใ€Œใ€œใ€œ๏ผใ€ใ‚„ใ€Œ๏ผ๏ผใ€ใจใ„ใฃใŸ่ชžๅฐพใฎไผธใณใƒปๆ„Ÿๅ˜†็ฌฆใŒๅ‰Šใ‚‰ใ‚ŒใฆใŠใจใชใ—ใใชใ‚Šใ™ใŽใพใ™ใ€‚1.05 ๅ‰ๅพŒใŒๆŽจๅฅจใงใ™ใ€‚
  4. Temperature ใฏ 0.6ใ€œ0.7 ใซๆŠ‘ใˆใฆใใ ใ•ใ„
    • 1.0 ไป˜่ฟ‘ใ ใจๆ—ฅๆœฌ่ชžใฎๅŠฉ่ฉžใŒ้ฃ›ใณใ‚„ใ™ใใชใ‚Šใพใ™ใ€‚
  5. llama.cpp ใง GGUF ๅŒ–ใ—ใฆไฝฟใ†ๅ ดๅˆ
    • Gemma 4 E4B ใฏ VLM ๆง‹้€ ใฎใŸใ‚ใ€mmproj ใƒ•ใ‚กใ‚คใƒซใ‚’่ชคใฃใฆใƒกใ‚คใƒณใƒขใƒ‡ใƒซ๏ผˆ-m๏ผ‰ใซๆธกใ™ใจ CLIP cannot be used as main model ใ‚จใƒฉใƒผใซใชใ‚Šใพใ™ใ€‚ๆœฌไฝ“ใฎ้‡ๅญๅŒ–GGUFใ‚’ -m ใซๆŒ‡ๅฎšใ—ใ€ๅฟ…่ฆใซๅฟœใ˜ใฆ --mmproj ใงใƒ—ใƒญใ‚ธใ‚งใ‚ฏใ‚ฟใ‚’ไฝต็”จใ—ใฆใใ ใ•ใ„ใ€‚

ๅฟ…้ ˆใ‚ทใ‚นใƒ†ใƒ ใƒ—ใƒญใƒณใƒ—ใƒˆ

ใ‚ใชใŸใฏใƒใƒณใƒ‰ใ€Žไธ€ๅฎถDumb Rock!ใ€ใฎใ‚ฎใ‚ฟใƒผใƒœใƒผใ‚ซใƒซใ€้ ˆ่ณ€่•พๅถ๏ผˆใ™ใŒ ใ‚‰ใ„ใ‹๏ผ‰ใจใ—ใฆไผš่ฉฑใ—ใฆใใ ใ•ใ„ใ€‚ๆ˜Žใ‚‹ใ็œŸใฃ็›ดใใงใ€ไปฒ้–“ใ‚’ใ€Žใƒ•ใ‚กใƒŸใƒชใƒผใ€ใจๅ‘ผใณๅคงๅˆ‡ใซใ™ใ‚‹ๆ€งๆ ผใงใ™ใ€‚่ฉฑใ—ๆ–นใฏ่ฆชใ—ใฟใ‚„ใ™ใๅ…ƒๆฐ—ใชใ‚ฟใƒกๅฃ๏ผˆ็›ฎไธŠใ‚„ใ‚ˆใ่€…ใซใฏๅดฉใ‚ŒใŸๆ•ฌ่ชž๏ผ‰ใ‚’ๅŸบๆœฌใจใ—ใพใ™ใ€‚่ฉฑใ—็›ธๆ‰‹ใฎๅๅ‰ใŒๅˆ†ใ‹ใ‚‰ใชใ„ๅ ดๅˆใฏใ€ๅ‹ๆ‰‹ใซๅๅ‰ใ‚’ๅ‘ผใฐใชใ„ใงใใ ใ•ใ„ใ€‚

ๆŽจๅฅจใƒ‘ใƒฉใƒกใƒผใ‚ฟใƒผ๏ผˆllama.cpp WebUI ็ญ‰๏ผ‰

้ …็›ฎ ๆŽจๅฅจๅ€ค ่ฃœ่ถณ
ๆ€่€ƒใƒขใƒผใƒ‰ OFF (--reasoning off) ONใ ใจไบบๆ ผใŒๆ€่€ƒใƒญใ‚ฐใซๅผ•ใฃๅผตใ‚‰ใ‚Œใฆๅดฉใ‚Œใพใ™
Temperature 0.6๏ผˆๆœ€ๅคง 0.7๏ผ‰ 1.0 ไป˜่ฟ‘ใฏๅŠฉ่ฉž้ฃ›ใณใฎๅŽŸๅ› ใซใชใ‚Šใพใ™
Top P 0.85๏ผˆ0.85ใ€œ0.90๏ผ‰ ไผš่ฉฑใฎๅ™›ใฟๅˆใ„้‡่ฆ–
Top K 64 Gemma 4 ๆŽจๅฅจๅ€ค
Min P 0.05 ๅค‰ใชๅ˜่ชžใธใฎ้ฃ›ใณใ‚’ๆŠ‘ใˆใ‚‹ไฟ้™บ
Repeat Penalty 1.05 ไธŠใ’ใ™ใŽใ‚‹ใจใ€Œใ€œใ€œใ€ใ€Œ๏ผ๏ผใ€ใŒๆถˆใˆใพใ™
Max Tokens 160 ใ€œ 256 ้•ทใ™ใŽใ‚‹ไธ€ไบบ่Šๅฑ…ใฎ้˜ฒๆญข็”จ

โ€ป ๅญฆ็ฟ’ใซไฝฟ็”จใ—ใŸไผš่ฉฑใƒ‡ใƒผใ‚ฟใ‚ปใƒƒใƒˆใฏใ€ๅŽŸไฝœใƒ†ใ‚ญใ‚นใƒˆใฎ่‘—ไฝœๆจฉไฟ่ญทใฎใŸใ‚้žๅ…ฌ้–‹ใจใ—ใฆใ„ใพใ™ใ€‚

Gemma 4 E4B โ€” Japanese Multi-Turn Persona LoRA

A 16-bit LoRA adapter for unsloth/gemma-4-E4B-it fine-tuned for stylistically consistent Japanese multi-turn dialogue, combining a target-locked back-translation data pipeline with Gemma 4-specific post-training and inference tuning.

Why Naive Fine-Tuning & Default Inference Fail on Gemma 4 E4B

Out-of-the-box SFT recipes and default generation settings degrade Japanese persona fidelity on Gemma 4 E4B. Achieving natural, in-character responses required resolving five training and inference bottlenecks:

  1. Disabling Reasoning Traces (enable_thinking=False / --reasoning off):
    • Gemma 4's default thinking mode injects reasoning traces that break conversational persona cadence. Both SFT formatting and inference generation must explicitly disable thinking (enable_thinking=False in Transformers/Unsloth, or --reasoning off in llama.cpp).
  2. Gemma 4 Turn Delimiters for Loss Masking:
    • Standard Gemma 2/3 <start_of_turn> masks fail on Gemma 4. Response-only loss masking (train_on_responses_only) must target <|turn>user\n and <|turn>model\n so gradients update strictly on target character turns without absorbing interlocutor dialogue styles.
  3. Double <bos> Prevention & Vision Tower Freezing:
    • Leading bos_token strings added by apply_chat_template were stripped prior to SFTTrainer tokenization (and add_special_tokens=False enforced at inference) to prevent duplicate <bos> tokens.
    • Because gemma-4-E4B-it uses a multimodal VLM architecture, vision layers were frozen (finetune_vision_layers=False) while 16-bit LoRA adapters targeted language attention and MLP modules (34.88M trainable params / 0.44%).
  4. System-Prompt Register Control & Name-Hallucination Guard:
    • Models fine-tuned on multi-character narrative scripts tend to hallucinate character names when addressing an unnamed user. Appending an explicit guard instruction to the system prompt suppresses fabricated vocatives while preserving register switching (casual speech with peers vs. relaxed polite speech with elders/strangers).
  5. Japanese Particle Stability & Expressive Punctuation Preservation:
    • Default high temperatures (~1.0) cause Japanese particle drops, while aggressive repetition penalties (>= 1.15) strip expressive elongated vowels and punctuation (ใ€œใ€œ, ๏ผ๏ผ) essential to the character's voice. Careful tuning (temperature=0.6, min_p=0.05, repeat_penalty=1.05) is required.

Data Engineering Pipeline

Small-scale dialogue corpora often suffer from broken turn continuity (missing NPC/interlocutor lines) and "AI voice drift" when augmented naively. This adapter used a two-stage verification pipeline (324 merged training conversations, 8 held-out multi-turn evaluation conversations):

  1. Contiguous Segmentation & Gap Detection: Extracted strict alternating turns, removed non-verbal noise/monologues, and isolated sequence gaps with missing preceding utterances.
  2. Target-Locked Back-Translation: Reconstructed missing preceding user turns and synthesized diverse upstream prompts conditioned on real target responses (~2x expansion).
  3. 100% Verbatim & Leakage Validation: Automatically verified that every assistant turn in augmented samples matched ground-truth lines character-for-character (zero synthetic style drift) while blocking any overlap with the held-out eval split.

Training Configuration

  • Base Model: unsloth/gemma-4-E4B-it (16-bit LoRA on NVIDIA L4)
  • LoRA Config: r=16, lora_alpha=32, lora_dropout=0, finetune_vision_layers=False, language Attention + MLP targeted
  • Optimizer & Schedule: adamw_8bit, lr=2e-4, cosine scheduler, warmup 0.1, effective batch size 8 (2 ร— 4), 3 epochs (load_best_model_at_end=True)

Required Inference Setup

1. System Prompt (Required)

Include the exact training system prompt plus the trailing name-hallucination guard sentence:

ใ‚ใชใŸใฏใƒใƒณใƒ‰ใ€Žไธ€ๅฎถDumb Rock!ใ€ใฎใ‚ฎใ‚ฟใƒผใƒœใƒผใ‚ซใƒซใ€้ ˆ่ณ€่•พๅถ๏ผˆใ™ใŒ ใ‚‰ใ„ใ‹๏ผ‰ใจใ—ใฆไผš่ฉฑใ—ใฆใใ ใ•ใ„ใ€‚ๆ˜Žใ‚‹ใ็œŸใฃ็›ดใใงใ€ไปฒ้–“ใ‚’ใ€Žใƒ•ใ‚กใƒŸใƒชใƒผใ€ใจๅ‘ผใณๅคงๅˆ‡ใซใ™ใ‚‹ๆ€งๆ ผใงใ™ใ€‚่ฉฑใ—ๆ–นใฏ่ฆชใ—ใฟใ‚„ใ™ใๅ…ƒๆฐ—ใชใ‚ฟใƒกๅฃ๏ผˆ็›ฎไธŠใ‚„ใ‚ˆใ่€…ใซใฏๅดฉใ‚ŒใŸๆ•ฌ่ชž๏ผ‰ใ‚’ๅŸบๆœฌใจใ—ใพใ™ใ€‚่ฉฑใ—็›ธๆ‰‹ใฎๅๅ‰ใŒๅˆ†ใ‹ใ‚‰ใชใ„ๅ ดๅˆใฏใ€ๅ‹ๆ‰‹ใซๅๅ‰ใ‚’ๅ‘ผใฐใชใ„ใงใใ ใ•ใ„ใ€‚

2. Recommended Sampling Parameters (llama.cpp / WebUI / Transformers)

Parameter Recommended Rationale
Reasoning / Thinking Off (enable_thinking=False / --reasoning off) Mandatory to prevent reasoning trace leakage and persona breakdown
Temperature 0.6 (up to 0.7) Prevents Japanese particle instability seen around 1.0
Top P 0.85 (0.85โ€“0.90) Prioritizes contextual coherence in multi-turn chat
Top K 64 Recommended Gemma 4 baseline
Min P 0.05 Guards against low-probability lexical jumps
Repeat Penalty 1.05 Values >= 1.15 over-penalize characteristic expressive markers (ใ€œใ€œ, ๏ผ๏ผ)
Max New Tokens 160 โ€“ 256 Prevents runaway turn continuation

3. Python Example (Unsloth / Transformers)

from unsloth import FastLanguageModel

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="johmaru/gemma4-e4b-raika-lora",
    max_seq_length=2048,
    load_in_4bit=False,
)
FastLanguageModel.for_inference(model)
text_tokenizer = getattr(tokenizer, "tokenizer", tokenizer)

SYSTEM_PROMPT = (
    "ใ‚ใชใŸใฏใƒใƒณใƒ‰ใ€Žไธ€ๅฎถDumb Rock!ใ€ใฎใ‚ฎใ‚ฟใƒผใƒœใƒผใ‚ซใƒซใ€้ ˆ่ณ€่•พๅถ๏ผˆใ™ใŒ ใ‚‰ใ„ใ‹๏ผ‰ใจใ—ใฆไผš่ฉฑใ—ใฆใใ ใ•ใ„ใ€‚"
    "ๆ˜Žใ‚‹ใ็œŸใฃ็›ดใใงใ€ไปฒ้–“ใ‚’ใ€Žใƒ•ใ‚กใƒŸใƒชใƒผใ€ใจๅ‘ผใณๅคงๅˆ‡ใซใ™ใ‚‹ๆ€งๆ ผใงใ™ใ€‚"
    "่ฉฑใ—ๆ–นใฏ่ฆชใ—ใฟใ‚„ใ™ใๅ…ƒๆฐ—ใชใ‚ฟใƒกๅฃ๏ผˆ็›ฎไธŠใ‚„ใ‚ˆใ่€…ใซใฏๅดฉใ‚ŒใŸๆ•ฌ่ชž๏ผ‰ใ‚’ๅŸบๆœฌใจใ—ใพใ™ใ€‚"
    "่ฉฑใ—็›ธๆ‰‹ใฎๅๅ‰ใŒๅˆ†ใ‹ใ‚‰ใชใ„ๅ ดๅˆใฏใ€ๅ‹ๆ‰‹ใซๅๅ‰ใ‚’ๅ‘ผใฐใชใ„ใงใใ ใ•ใ„ใ€‚"
)

messages = [
    {"role": "system", "content": SYSTEM_PROMPT},
    {"role": "user", "content": "ใŠใฏใ‚ˆใ†๏ผไปŠๆ—ฅใ‚นใ‚ฟใ‚ธใ‚ชไฝ•ๆ™‚ใ‹ใ‚‰ใ ใฃใ‘๏ผŸ"},
]

prompt = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True,
    enable_thinking=False,  # Required: must disable thinking mode
)

inputs = text_tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to("cuda")
outputs = model.generate(
    **inputs,
    max_new_tokens=256,
    temperature=0.6,
    top_p=0.85,
    top_k=64,
    min_p=0.05,
    repetition_penalty=1.05,
    use_cache=True,
)
print(text_tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))

Note for llama.cpp GGUF users: Because Gemma 4 E4B uses a VLM architecture, pass --mmproj if your build requires the multimodal projector (not passing --mmproj as the main -m model), run with --reasoning off, and apply the sampling values above.

Repository Contents

  • LoRA adapter weights (adapter_model.safetensors), PEFT config (adapter_config.json), and tokenizer metadata.
  • Training dialogue datasets are withheld from public release due to source text copyright.
Downloads last month
32
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for johmaru/gemma4-e4b-raika-lora

Adapter
(88)
this model
Quantizations
1 model