Downloads · 30 days
24
2% of all-time downloads
thangvip/qwen3-4b-vietnamese-legal-grpo-phase-2
qwen3-4b-vietnamese-legal-grpo-phase-2 is a text generation model from thangvip. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
This is a Phase 2 Vietnamese legal reasoning specialist fine-tuned using Group Relative Policy Optimization (GRPO) on hard difficulty Vietnamese legal question-answering data. This model builds upon the Phase 1 traini…
Downloads · 30 days
24
2% of all-time downloads
All-time downloads
1.1K
Public
Parameters
4B
8.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors8 GB · 100%
From the Hugging Face model README
This is a Phase 2 Vietnamese legal reasoning specialist fine-tuned using Group Relative Policy Optimization (GRPO) on hard difficulty Vietnamese legal question-answering data. This model builds upon the Phase 1 training and is specifically designed to handle more complex syllogistic reasoning for challenging Vietnamese legal scenarios.
✅ Phase 2 Training: Advanced model trained on hard difficulty legal questions
✅ Syllogistic Reasoning: Structured legal arguments (Major Premise → Minor Premise → Conclusion)
✅ Vietnamese Legal Domain: Trained on Vietnamese legal texts and Q&A
✅ GRPO Optimization: Advanced policy optimization for better reasoning
✅ Citation Support: Generates responses with legal citations
✅ Structured Output: Uses XML-like tags for organized responses
✅ Extended Context: Supports up to 8192 tokens for complex reasoning chains
pip install transformers torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load model and tokenizer
model_name = "thangvip/qwen3-4b-vietnamese-legal-grpo-phase-2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
# Format your legal question
system_prompt = """Bạn là một chuyên gia pháp lý. Hãy trả lời câu hỏi bằng cách sử dụng phương pháp lập luận tam đoạn luận (syllogism).
Trước tiên, hãy suy nghĩ về vấn đề trong thẻ <think></think>.
Sau đó, trả lời theo định dạng sau:
<answer>
<major_premise>[Quy định pháp luật chung]</major_premise>
<minor_premise>[Sự kiện cụ thể trong câu hỏi]</minor_premise>
<conclusion>[Áp dụng quy định vào sự kiện để đưa ra kết luận]</conclusion>
</answer>
Hãy đảm bảo trích dẫn chính xác các điều luật liên quan."""
question = "Một công ty có nghĩa vụ gì khi sa thải nhân viên do tái cơ cấu?"
# Create conversation
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": question}
]
# Generate response
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=2048, # Extended for hard difficulty complex reasoning
temperature=0.7,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
print(response)
from transformers import pipeline
# Create text generation pipeline
generator = pipeline(
"text-generation",
model="thangvip/qwen3-4b-vietnamese-legal-grpo-phase-2",
tokenizer="thangvip/qwen3-4b-vietnamese-legal-grpo-phase-2",
torch_dtype=torch.bfloat16,
device_map="auto"
)
# Generate legal reasoning
prompt = "Câu hỏi: Quyền và nghĩa vụ của người thuê nhà khi hợp đồng thuê hết hạn?"
result = generator(prompt, max_new_tokens=512, temperature=0.7)
print(result[0]['generated_text'])
hard_level_qa.jsonlPhase 1: Initial GRPO training on normal difficulty questions
thangvip/qwen3-4b-legal-pretrain-synthetic-8k or similarnormal_level_qa.jsonlPhase 2 (This Model): Continued training on hard difficulty questions with extended context window
thangvip/qwen3-4b-vietnamese-legal-grpo)hard_level_qa.jsonlThis progressive training approach allows the model to first master basic legal reasoning before tackling more complex, multi-step legal problems.
The model was trained with a sophisticated reward system:
The model generates structured responses in this format:
<think>
[Internal reasoning about the legal question]
</think>
<answer>
<major_premise>
[General legal rule or principle applicable to the situation]
</major_premise>
<minor_premise>
[Specific facts from the question that relate to the legal rule]
</minor_premise>
<conclusion>
[Legal conclusion that follows logically from applying the rule to the facts]
</conclusion>
</answer>
If you use this model, please cite:
@misc{vietnamese-legal-grpo-2024,
title={Vietnamese Legal Reasoning Model with GRPO},
author={Your Name},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/thangvip/qwen3-4b-vietnamese-legal-grpo-phase-2}
}
Contributions are welcome! Please see our contributing guidelines.
This model is released under the Apache 2.0 License.
Note: This model is for educational and research purposes. Always consult qualified legal professionals for actual legal advice.