Downloads · 30 days
11
10% of all-time downloads
AmirMohseni/legalbert-primary_topic
legalbert-primary_topic 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 assigns a primary legal topic to a multi-turn conversation.
Downloads · 30 days
11
10% of all-time downloads
All-time downloads
111
Public
Parameters
109M
1.3 GB 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 assigns a primary legal topic to a multi-turn conversation.
Part of the Legal QA collection.
Stage 2 of the Legal-BERT routing pipeline. Pair with legalbert-seeks_guidance and only trust the topic label when stage 1 predicts legal guidance.
Input preprocessing: user messages only, serialized as User: content lines (assistant turns are dropped). Legal-BERT uses 512-token truncation.
Same 14 legal topics plus (non-guidance) as modernbert-primary_topic.
| Split | N | Accuracy | Precision | Recall | F1 |
|---|---|---|---|---|---|
| Validation (best checkpoint) | 106 | 79.25% | 78.88% | 79.25% | 78.42% |
| Test (held-out) | 107 | 78.50% | 81.45% | 78.50% | 78.65% |
Joint pipeline test (with legalbert-seeks_guidance): legal 84.1%, topic 72.0%, joint 72.0%.
from transformers import AutoModelForSequenceClassification, AutoTokenizer
model_id = "AmirMohseni/legalbert-primary_topic"
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)
See legalbert-seeks_guidance for a full two-stage example.
Use for: topic routing baseline at 512 tokens after legal-guidance detection.
Caveats: truncation; silver labels; English only.
Dataset: AmirMohseni/WildChat-Legal-Classification-V2-Balanced
primary_topic (empty for non-guidance rows)Selected from a hyperparameter sweep. See legalbert_classifier_sweep_colab.ipynb.
| Setting | Value |
|---|---|
| Base model | nlpaueb/legal-bert-base-uncased |
| Input mode | User turns only |
| Max length | 512 |
| Learning rate | 1e-4 |
| Epochs | 8 |
| Effective batch size | 128 (32 × 4 grad accum) |
| Best checkpoint | Highest validation accuracy (79.25%) |