One of 13 models in a controlled study of how far a small language model can be pushed on US legal and financial text. Every version was trained on the same data, evaluated on the same frozen held-out set, and scored by the same blind LLM judge, so the stages are directly comparable. Compare them side by side in the
SLM Arena.
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
4
5BASE = "google/gemma-2-2b-it" # gated — accept the licence first
6ADAPTER = "Ace-2504/gemma-2-2b-sft-dpo"
7
8bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type='nf4',
9 bnb_4bit_compute_dtype=torch.bfloat16,
10 bnb_4bit_use_double_quant=True)
11base = AutoModelForCausalLM.from_pretrained(
12 BASE, quantization_config=bnb, attn_implementation='eager',
13 torch_dtype=torch.bfloat16)
14model = PeftModel.from_pretrained(base, ADAPTER).eval()
15tok = AutoTokenizer.from_pretrained(BASE)
16
17SYS = ('You are a precise legal and financial assistant. Answer clearly using the '
18 'provided context; do not invent facts.')
19user = 'Context:\n<passage>\n\nQuestion: <your question>'
20text = tok.apply_chat_template([{'role': 'user', 'content': f'{SYS}\n\n{user}'}],
21 tokenize=False, add_generation_prompt=True)
22ids = tok(text, return_tensors='pt').to(model.device)
23# Gemma-2's hybrid cache misbehaves here — use_cache=False is required.
24out = model.generate(**ids, max_new_tokens=160, use_cache=False)
25print(tok.decode(out[0, ids['input_ids'].shape[1]:], skip_special_tokens=True))
The 0–10 figure is a four-dimension rubric (correctness 0–5 + completeness 0–2 + groundedness 0–2 + clarity 0–1). The 0–1 figure is the stricter correctness-only scale used in the experiment reports. Same questions, same answers, same judge — different scale, so the two numbers differ.
All under
Ace-2504 except the two imported bases.
This model has its own write-up — training details, cost breakdown and live demo — at
https://slm-gemma-dpo-harman.vercel.app.
1@misc{sandhu2026slm,
2 title = {Small Language Models for Legal and Financial Text: a controlled study of
3 pretraining, instruction tuning, retrieval augmentation and alignment},
4 author = {Harman Sandhu},
5 year = {2026},
6 note = {https://slm-arena-harman.vercel.app}
7}