Fine-tuned
Google Gemma 4 E4B for legal analysis using GRPO (Group Relative Policy Optimization) reinforcement learning.
Legal-domain LoRA adapter trained with GRPO reinforcement learning on 45K+ legal/reasoning examples. Optimized for legal document analysis, statute interpretation, evidence classification, and case law reasoning with proper Bluebook citations.
1from unsloth import FastVisionModel
2from peft import PeftModel
3
4model, tokenizer = FastVisionModel.from_pretrained(
5 model_name="unsloth/gemma-4-E4B-it-unsloth-bnb-4bit",
6 max_seq_length=4096,
7 load_in_4bit=True,
8)
9model = PeftModel.from_pretrained(model, "Semaj90/gemma4-e4b-legal-grpo")
10FastVisionModel.for_inference(model)
11
12messages = [{"role": "user", "content": [{"type": "text", "text": "Analyze 42 U.S.C. Section 1983"}]}]
13inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
14output = model.generate(input_ids=inputs, max_new_tokens=512, temperature=0.7)
15print(tokenizer.decode(output[0], skip_special_tokens=True))
1# See: Semaj90/gemma4-e4b-legal-grpo-GGUF
2ollama create gemma4-legal:latest -f Modelfile
3ollama run gemma4-legal:latest "What are the elements of negligence?"
45K+ examples distilled into 1,000 GRPO prompts (Phase 1 pilot).
The original training produced 884 tensors (588 language + 224 vision + 72 audio). Despite
finetune_vision_layers=False, generic
target_modules (
q_proj,
k_proj, etc.) matched projections across all sub-models. The vision/audio tensors use
Gemma4ClippableLinear which PEFT cannot merge (
upstream issue).
1@misc{gemma4-legal-grpo-2026,
2 title={Gemma 4 E4B Legal GRPO Adapter},
3 author={Semaj90},
4 year={2026},
5 url={https://huggingface.co/Semaj90/gemma4-e4b-legal-grpo}
6}