Downloads · 30 days
12
24% of all-time downloads
abhishekai/gemma-2-2b-legal-rm
gemma-2-2b-legal-rm is a text classification model from abhishekai. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as gemma.
A 2.61B-parameter scalar reward model for grounded legal/financial Q&A, trained on AI-generated preferences (RLAIF), derived from Gemma-2-2B.
Downloads · 30 days
12
24% of all-time downloads
All-time downloads
50
Public
Parameters
2.6B
10.5 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors10.5 GB · 100%
From the Hugging Face model README
A 2.61B-parameter scalar reward model for grounded legal/financial Q&A, trained on AI-generated preferences (RLAIF), derived from Gemma-2-2B.
This is not a chat model. It emits a single scalar per sequence and cannot
generate text. Load it with AutoModelForSequenceClassification, not
AutoModelForCausalLM.
This model is a derivative of Google's Gemma-2-2B. Google's
Gemma Terms of Use and
Prohibited Use Policy
travel with every derivative and apply to your use of this model. It is
published under license: gemma and may not be redistributed as Apache-2.0
or as unlicensed.
Every generating checkpoint in this project was re-scored by a Claude Sonnet judge on
four axes out of 10 over a shared set of 300 held-out prompts. A reward model has no
cell in that table: it emits a scalar preference score rather than an answer, so there
is nothing for an answer-quality rubric to grade. Its pairwise accuracy above remains the
relevant measure. The full table is in MODEL_INDEX.md in the project repository.
Given a rendered prompt concatenated with a candidate answer, it returns one number. Higher means "closer to what Gemini 2.5 Flash preferred." Only differences between scores are meaningful — the Bradley-Terry objective it was trained with fixes score gaps, not absolute magnitude, so the raw value is arbitrary and not comparable across reward models. (This one happens to emit scores on the order of ~28 where the 125M's emit ~1; that difference carries no information about quality, and mistaking it for signal is precisely what broke the first PPO run built on it.)
| pairwise accuracy on held-out preference pairs | 0.875 — the best of the three |
| architecture | Gemma-2-2B SFT backbone + fresh scalar head (num_labels=1) |
| training objective | -log σ(r(prompt+chosen) − r(prompt+rejected)) |
| preference pairs | 628 triplets (528 train / 100 eval) |
| learning rate | 3e-6 (1e-5 memorized the set outright) |
Gemma-2's chat template raises on a system role, so the system prompt is
folded into the user turn, and an assistant turn ends with <end_of_turn>,
not <eos>.
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
name = "abhishekai/gemma-2-2b-legal-rm"
tok = AutoTokenizer.from_pretrained(name)
rm = AutoModelForSequenceClassification.from_pretrained(
name, num_labels=1, torch_dtype=torch.bfloat16).eval()
rm.config.pad_token_id = tok.convert_tokens_to_ids("<pad>")
SYSTEM = "You are a precise legal and financial assistant. Answer only from the provided context."
def score(question, context, answer):
user = f"{SYSTEM}\n\nContext: {context}\n\nQuestion: {question}"
prompt = tok.apply_chat_template([{"role": "user", "content": user}],
tokenize=False, add_generation_prompt=True)
enc = tok(prompt + answer.strip() + "<end_of_turn>", add_special_tokens=False,
return_tensors="pt", truncation=True, max_length=1024)
# input_ids/attention_mask only — the tokenizer also emits token_type_ids,
# which the SequenceClassification forward() rejects.
with torch.no_grad():
return rm(input_ids=enc["input_ids"],
attention_mask=enc["attention_mask"]).logits.squeeze().item()
Scoring a differently-formatted string puts the model out of distribution and the number becomes meaningless without any error being raised.
628 preference triplets built on-policy from the frozen Gemma-2-2B SFT model: