Downloads · 30 days
0
hoailebads/Qwen3-Embedding-0.6B-VLSP-Legal-Retrieval-LoRA
Qwen3-Embedding-0.6B-VLSP-Legal-Retrieval-LoRA is a feature extraction model from hoailebads. Use it when you need embeddings to search or compare text. It is set up for peft. The card lists the license as apache-2.0.
Bi-encoder truy hồi điều luật tiếng Việt cho bài toán VLSP Legal Text Retrieval. Kiến trúc dual-LoRA: hai adapter LoRA riêng biệt dùng chung một base model đóng băng — queryadapter mã hoá câu hỏi, passageadapter mã ho…
Downloads · 30 days
0
Access
Public
Updated Aug 20, 2026
Repo size
80.8 MB
Likes
0
Public
Click a slice to open those files.
.safetensors80.8 MB · 100%
From the Hugging Face model README
Bi-encoder truy hồi điều luật tiếng Việt cho bài toán VLSP Legal Text Retrieval.
Kiến trúc dual-LoRA: hai adapter LoRA riêng biệt dùng chung một base model đóng băng —
query_adapter mã hoá câu hỏi, passage_adapter mã hoá điều luật.
Đây là checkpoint retrieval tốt nhất trong 22 lần train được đo trên cùng tập eval
(train_synthetic_hoi_dap), dùng để sinh top-100 candidate cho pha rerank trong
hoaileba/Qwen-Retrieval-Tuning.
Tập eval: 219 câu hỏi unique (VLSP eval.json, ground truth dedup theo aid).
Corpus: 67,561 chunk / 59,628 điều luật. FAISS inner-product, dedup theo aid.
| K | Recall@K | Precision@K | Hit@K |
|---|---|---|---|
| 1 | 45.81 | 52.97 | 52.97 |
| 3 | 62.60 | 25.27 | 71.69 |
| 5 | 69.29 | 16.99 | 79.00 |
| 10 | 80.90 | 10.18 | 89.95 |
| 100 | 94.98 | 1.25 | 98.63 |
R@100 = 94.98 là trần recall cho pha rerank phía sau — ~5% câu hỏi không có đáp án đúng trong 100 candidate, và đó là giới hạn thật của pipeline chứ không phải của reranker.
| Run | R@1 | R@10 | R@100 |
|---|---|---|---|
train_synthetic_hoi_dap ← model này | 45.81 | 80.90 | 94.98 |
train_synthetic_only_hn (checkpoint cha) | 44.22 | 81.28 | 94.18 |
train_dual_syn_ques_filtered_cont | 44.22 | 77.82 | 94.98 |
train_dual_vlsp_only_original | 43.61 | 78.77 | 94.33 |
train_synthetic_binh_dan | 42.62 | 81.20 | 93.42 |
train_synthetic_dong_nghia_new | 42.54 | 81.43 | 94.03 |
single-adapter LoRA (train_single_vlsp_only) | 41.02 | 79.22 | 94.10 |
fast_cached_mnrl_hn_dual_syn_ques (bản sớm) | 32.99 | 68.38 | 86.68 |
Hai điều đọc được từ bảng: dual-adapter hơn single-adapter (+4.8 R@1 so với
train_single_vlsp_only), và augment câu hỏi dạng hỏi–đáp (hoi_dap) là biến thể synthetic
cho lợi ích lớn nhất — cộng thêm +1.6 R@1 lên trên checkpoint cha train_synthetic_only_hn.
Số đo đầy đủ: eval_results.json.
Model gồm hai adapter nên không load thẳng bằng AutoModel được — phải nạp cả hai và
chuyển adapter theo loại text. File modeling_dual_lora.py trong repo
này làm sẵn việc đó:
from modeling_dual_lora import DualLoRAEncoder
import numpy as np
enc = DualLoRAEncoder.from_pretrained("hoailebads/Qwen3-Embedding-0.6B-VLSP-Legal-Retrieval-LoRA")
questions = ["Người điều khiển xe máy không đội mũ bảo hiểm bị phạt bao nhiêu tiền?"]
articles = ["Điều 6. Xử phạt người điều khiển xe mô tô, xe gắn máy ... "]
q = enc.encode(questions, is_query=True) # (1, 1024), đã L2-normalize
d = enc.encode(articles, is_query=False) # (N, 1024)
scores = q @ d.T # inner product == cosine
top = np.argsort(-scores[0])[:10]
Hoặc tự nạp bằng PEFT:
from transformers import AutoModel, AutoTokenizer
from peft import PeftModel
import torch
base = AutoModel.from_pretrained("Qwen/Qwen3-Embedding-0.6B",
torch_dtype=torch.bfloat16, trust_remote_code=True)
model = PeftModel.from_pretrained(base, "<repo>/query_adapter", adapter_name="query_adapter")
model.load_adapter("<repo>/passage_adapter", adapter_name="passage_adapter")
model.set_adapter("query_adapter") # trước khi encode câu hỏi
model.set_adapter("passage_adapter") # trước khi encode điều luật
"Instruct: ..." sẽ lệch phân bố.max_length = 1024, truncation bên phải (mặc định của tokenizer).article_title + "\n" + content.passage_adapter (hoặc ngược lại) làm hỏng kết quả — đây là lỗi dễ mắc
nhất khi dùng model này.| Base model | Qwen/Qwen3-Embedding-0.6B (đóng băng) |
| LoRA | r=16, alpha=32, dropout=0.05, target = q,k,v,o,gate,up,down_proj |
| Trainable | 20,185,088 / 615,961,600 params (3.28%), ×2 adapter |
| Loss | fast_cached_mnrl_dual — cached multiple-negatives ranking, temperature=0.05 |
| Hard negatives | 1/query (mine từ chính checkpoint cha) |
| Batch size | 256 (cached mini-batch 16) |
| Epochs / steps | 5 epochs, 20 optimizer steps |
| Precision | bf16 + Flash Attention 2, 2×GPU torchrun |
| Resume từ | output/train_synthetic_only_hn (huấn luyện nối tiếp nhiều pha) |
| Train loss | 1.5675 → 1.3703 |
| Dataset | 2,038 sample — VLSP gốc + câu hỏi synthetic biến thể hỏi–đáp |
Model là kết quả của một chuỗi train nối tiếp, không phải một lần train từ base: mỗi pha
mine lại hard negative bằng checkpoint ngay trước đó rồi train tiếp trên một biến thể synthetic
mới. train_synthetic_hoi_dap là pha cuối của nhánh thắng.
câu hỏi → [RETRIEVAL: model này] → top-100 → [RERANK: Qwen3-Reranker-8B] → dynamic top-k → đáp án
Model liên quan:
hoailebads/Qwen3-Reranker-8B-VLSP-Legal-LoRA — reranker chínhhoailebads/Qwen3-Reranker-0.6B-VLSP-Legal-LoRA — reranker bản nhẹhoailebads/Qwen3-Embedding-0.6B-Zalo-Legal-Retrieval-LoRA — bản retrieval cho corpus ZaloCode + số đo đầy đủ: hoaileba/Qwen-Retrieval-Tuning
Apache-2.0, theo base model Qwen/Qwen3-Embedding-0.6B.