legal_consult_phobert
legal_consult_phobert is a Vietnamese text classification model fine-tuned from vinai/phobert-base-v2 for a routing task: deciding whether a user utterance should be treated as a legal consultation request or as general conversation.
The model predicts one of two labels:
LEGAL_CONSULT
GENERAL_CONVERSATION
This model is intended for upstream intent routing in a legal assistant pipeline, not for generating legal advice by itself.
Model Details
- Base model:
vinai/phobert-base-v2
- Architecture:
RobertaForSequenceClassification
- Language: Vietnamese
- Max sequence length:
256
- Labels:
0 -> GENERAL_CONVERSATION
1 -> LEGAL_CONSULT
Intended Use
Use this model when you need to detect whether a Vietnamese input should be routed into a legal consultation workflow.
Typical use cases:
- Pre-routing messages before sending them to a legal QA or legal RAG system
- Filtering mixed chat streams into legal vs non-legal requests
- Triggering specialized downstream handling for law-related questions
This model is especially suitable as a lightweight intent classifier in front of a larger legal assistant stack.
Out-of-Scope Use
This model should not be treated as:
- A legal answer generation model
- A substitute for professional legal advice
- A full multi-intent classifier for all Vietnamese domains
Outputs only indicate whether the input resembles a legal consultation request under the training setup used here.
Training Data
The model was trained on a custom Vietnamese routing dataset built for binary classification between legal consultation and general conversation.
Verified split sizes used in training:
- Train:
40,562
- Validation:
3,528
- Test:
3,551
Observed label distribution:
- Train:
17,746 general, 22,816 legal
- Validation:
1,690 general, 1,838 legal
- Test:
1,681 general, 1,870 legal
Main source prefixes observed in the corpus:
alqac_paraphased
UIT-ViQuAD2.0
manual_general_templates
Observed augmentation styles:
original
khong_dau_local
sai_chinh_ta_local
Training Procedure
Training was performed with the Hugging Face Trainer API.
Key settings:
- Learning rate:
2e-5
- Train batch size per device:
16
- Eval batch size per device:
32
- Number of epochs:
4
- Weight decay:
0.01
- Warmup ratio:
0.1
- Early stopping patience:
2
- Seed:
42
- Mixed precision: enabled when CUDA is available
The preprocessing pipeline used Vietnamese word segmentation before tokenization for PhoBERT-based training.
Evaluation
Validation
- Accuracy:
0.9983
- Precision:
0.9995
- Recall:
0.9973
- F1:
0.9984
- Loss:
0.0110
Test
- Accuracy:
0.9966
- Precision:
0.9936
- Recall:
1.0000
- F1:
0.9968
- Loss:
0.0203
These results indicate that the model is highly effective for the binary routing setup represented in the training and evaluation data.
Example
Input:
Toi muon hoi thu tuc khoi kien tranh chap hop dong lao dong can nhung giay to nao?
Expected behavior:
- Predicted label:
LEGAL_CONSULT
Input:
Ban goi y cho minh mot vai bai nhac de tap trung hoc bai duoc khong?
Expected behavior:
- Predicted label:
GENERAL_CONVERSATION
Usage
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_id = "mrbut/cls-consulting-law-phoBERT"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
7model = AutoModelForSequenceClassification.from_pretrained(model_id)
8
9text = "Toi muon hoi thu tuc khoi kien tranh chap hop dong lao dong can nhung giay to nao?"
10inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
11
12with torch.no_grad():
13 logits = model(**inputs).logits
14 probs = torch.softmax(logits, dim=-1)[0]
15
16pred_id = int(torch.argmax(probs))
17print(model.config.id2label[pred_id], float(probs[pred_id]))
Limitations
- Performance is reported on the author's custom binary routing dataset, so real-world results may degrade on noisier or broader user inputs.
- The model is optimized for Vietnamese text and may not generalize well to mixed-language or non-Vietnamese content.
- It only predicts two classes, so ambiguous requests may still require downstream fallback logic or confidence thresholds.
- The model does not verify legal correctness and should not be used as the final authority in legal decision-making.
Recommended Deployment Pattern
A practical pattern is:
- Run this classifier on the incoming user message.
- If prediction is
LEGAL_CONSULT, route to a legal retrieval or legal QA pipeline.
- If prediction is
GENERAL_CONVERSATION, handle with a general chat workflow.
- If confidence is low, send to a fallback or human-review path.
Acknowledgements
- Base model:
vinai/phobert-base-v2
- Built with Hugging Face Transformers