VLegal-Bench: Cognitively Grounded Benchmark for Vietnamese Legal Reasoning of Large Language Models
Paper • 2512.14554 • Published • 1
How to use datht/viet-legal-4B with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="datht/viet-legal-4B")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("datht/viet-legal-4B", dtype="auto")How to use datht/viet-legal-4B with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "datht/viet-legal-4B"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "datht/viet-legal-4B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/datht/viet-legal-4B
How to use datht/viet-legal-4B with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "datht/viet-legal-4B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "datht/viet-legal-4B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "datht/viet-legal-4B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "datht/viet-legal-4B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use datht/viet-legal-4B with Docker Model Runner:
docker model run hf.co/datht/viet-legal-4B
A Vietnamese Legal SLM fine-tuned from Qwen/Qwen3-4B on the VLegal-Bench dataset using QLoRA.
| Metric | Value |
|---|---|
| loss (epoch 1) | 0.7023 |
| runtime (epoch 1) | 610.3857 |
| samples_per_second (epoch 1) | 2.0070 |
| steps_per_second (epoch 1) | 0.5030 |
| loss (epoch 2) | 0.6648 |
| runtime (epoch 2) | 609.0622 |
| samples_per_second (epoch 2) | 2.0110 |
| steps_per_second (epoch 2) | 0.5040 |
| Parameter | Value |
|---|---|
| Base model | Qwen/Qwen3-4B |
| Dataset | legal-combined (11025 train / 1225 eval) |
| LoRA rank | 16 |
| LoRA alpha | 32 |
| Learning rate | 0.0002 |
| Epochs | 3 |
| Batch size | 1 x 8 (effective: 8) |
| Precision | fp16 |
| Max seq length | 1024 |
| Training time | N/A |
| Best epoch | 2 |
| Hardware | Kaggle T4 (16GB VRAM) |
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "datht/viet-legal-4B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
messages = [
{"role": "system", "content": "Bạn là một trợ lý pháp luật Việt Nam."},
{"role": "user", "content": "Hành vi trộm cắp tài sản trị giá 5 triệu đồng bị xử lý như thế nào?"},
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
VLegal-Bench — A cognitively grounded benchmark for Vietnamese legal reasoning, comprising 10,467 samples across 22 tasks organized into 5 categories:
Trained with nlp-trainer using Unsloth + TRL SFTTrainer with QLoRA on Kaggle T4 GPU.
@misc{dong2025vlegalbench,
title={VLegal-Bench: Cognitively Grounded Benchmark for Vietnamese Legal Reasoning of Large Language Models},
author={Nguyen Tien Dong and others},
year={2025},
eprint={2512.14554},
archivePrefix={arXiv},
}