Views
No views yet
unsloth/gemma-4-E4B-it (trained on the unsloth/gemma-4-E4B-it-unsloth-bnb-4bit 4-bit variant)r=16, alpha=16), language layers only| Metric | Base Gemma 4 | + this LoRA | Δ |
|---|---|---|---|
| Overall Exact Match | 56.2 | 76.2 | +20.0 |
| Overall token-F1 | 73.9 | 89.4 | +15.6 |
| Answerable Exact Match | 15.0 | 55.0 | +40.0 |
| Answerable token-F1 | 50.2 | 81.4 | +31.1 |
| Not-found abstention acc | 97.5 | 97.5 | +0.0 |
1import torch
2from transformers import AutoModelForImageTextToText, AutoProcessor
3from peft import PeftModel
4
5BASE = "unsloth/gemma-4-E4B-it"
6ADAPTER = "soybelli/gemma-4-E4B-it-cuad-lora"
7
8processor = AutoProcessor.from_pretrained(BASE)
9model = AutoModelForImageTextToText.from_pretrained(BASE, torch_dtype=torch.bfloat16, device_map="auto")
10model = PeftModel.from_pretrained(model, ADAPTER).eval()
11
12SYSTEM = (
13 "You are a legal contract review assistant. Read the contract excerpt and answer the question. "
14 "If the relevant clause is present, quote the exact text from the excerpt. "
15 "If it is not present, reply exactly: Not found."
16)
17excerpt = "...THIS AGREEMENT shall be governed by and construed in accordance with the laws of the State of New York..."
18question = (
19 'Highlight the parts (if any) of this contract related to "Governing Law" that should be reviewed by a '
20 "lawyer. Details: Which state/country's law governs the interpretation of the contract?"
21)
22prompt = f"{SYSTEM}\n\n### Contract excerpt:\n{excerpt}\n\n### Question:\n{question}\n\n### Answer:"
23
24messages = [{"role": "user", "content": [{"type": "text", "text": prompt}]}]
25inputs = processor.apply_chat_template(
26 messages, add_generation_prompt=True, tokenize=True, return_tensors="pt", return_dict=True
27).to(model.device)
28out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
29print(processor.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip())CUAD_v1/CUAD_v1.json), flattened to (excerpt, question, answer) pairs.
Excerpts are ~2,400-char windows centered on the answer span; the natural ~32% answerable / 68% not-found
distribution is kept. 18,759 training examples (10% of contracts held out for eval).max_seq_length=1024, effective batch 16, lr 2e-4, adamw_8bit, bf16, trained only on
the assistant response. Final train loss ≈ 0.14.