Downloads · 30 days
7
7% of all-time downloads
AmirMohseni/legalbert-seeks_guidance
legalbert-seeks_guidance is a text classification model from AmirMohseni. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as apache-2.0.
Fine-tuned Legal-BERT classifier that detects whether a user in a multi-turn conversation is seeking legal guidance.
Downloads · 30 days
7
7% of all-time downloads
All-time downloads
103
Public
Parameters
109M
438 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors438 MB · 100%
From the Hugging Face model README
Fine-tuned Legal-BERT classifier that detects whether a user in a multi-turn conversation is seeking legal guidance.
Part of the Legal QA collection.
Stage 1 of a two-model Legal-BERT routing pipeline:
| Stage | Model | Input | Output |
|---|---|---|---|
| 1 | legalbert-seeks_guidance | User turns only | seeks_legal_guidance (True/False) |
| 2 | legalbert-primary_topic | User turns only | Primary legal topic (14 labels + non-guidance) |
Legal-BERT is trained with 512-token truncation. Long WildChat threads are truncated from the start, which is a known limitation compared to long-context encoders such as ModernBERT.
| Split | N | Accuracy | Precision | Recall | F1 |
|---|---|---|---|---|---|
| Validation (best checkpoint) | 106 | — | — | — | 91.51% |
| Test (held-out) | 107 | 84.11% | 84.11% | 84.11% | 84.10% |
Joint pipeline test (with legalbert-primary_topic): legal 84.1%, topic 72.0%, joint 72.0%.
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
def serialize(messages, input_mode="user"):
lines = []
for msg in messages:
role = msg["role"]
if input_mode == "user" and role != "user":
continue
lines.append(f"{role.capitalize()}: {msg['content']}")
return "\n".join(lines)
model_id = "AmirMohseni/legalbert-seeks_guidance"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)
input_mode = getattr(model.config, "legal_cls_input_mode", "user")
max_length = getattr(model.config, "legal_cls_max_length", 512)
text = serialize(conversation, input_mode=input_mode)
enc = tokenizer(text, truncation=True, max_length=max_length, return_tensors="pt")
with torch.no_grad():
pred_id = model(**enc).logits.argmax(dim=-1).item()
print(model.config.id2label[str(pred_id)])
Use for: encoder baseline comparisons on English legal routing at 512 tokens.
Do not use for: legal advice or deployment without evaluation on your traffic.
Caveats: silver GPT-5.4 labels; severe truncation on long conversations.
Dataset: AmirMohseni/WildChat-Legal-Classification-V2-Balanced
Selected from a 24-trial hyperparameter sweep (LR × input mode × effective batch). See legalbert_classifier_sweep_colab.ipynb.
| Setting | Value |
|---|---|
| Base model | nlpaueb/legal-bert-base-uncased |
| Input mode | User turns only (beat full conversation in sweep) |
| Max length | 512 |
| Learning rate | 1e-4 |
| Epochs | 8 |
| Effective batch size | 32 |
| Best checkpoint | Highest validation weighted F1 (91.51%) |
Sweep note: all top-9 validation runs used user input; best full-conversation run reached only 88.67% F1.