Views
No views yet
AutoModelForSequenceClassification, not
AutoModelForCausalLM.| pairwise accuracy on held-out preference pairs | 0.820 |
| architecture | SFT backbone + fresh scalar head (num_labels=1) |
| training objective | -log σ(r(prompt+chosen) − r(prompt+rejected)) |
| preference pairs | 994 triplets (894 train / 100 eval) |
MODEL_INDEX.md in the project repository.1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4name = "abhishekai/slm-500m-legal-rm"
5tok = AutoTokenizer.from_pretrained(name)
6rm = AutoModelForSequenceClassification.from_pretrained(name, num_labels=1).eval()
7rm.config.pad_token_id = tok.convert_tokens_to_ids("<|pad|>")
8
9def score(question, context, answer):
10 msgs = [
11 {"role": "system", "content": "You are a precise legal and financial assistant. Answer only from the provided context."},
12 {"role": "user", "content": f"Context: {context}\n\nQuestion: {question}"},
13 ]
14 prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
15 enc = tok(prompt + answer.strip() + "<|eos|>", add_special_tokens=False,
16 return_tensors="pt", truncation=True, max_length=1024)
17 # input_ids/attention_mask only — the tokenizer also emits token_type_ids,
18 # which LlamaForSequenceClassification.forward() rejects.
19 with torch.no_grad():
20 return rm(input_ids=enc["input_ids"],
21 attention_mask=enc["attention_mask"]).logits.squeeze().item()