Downloads · 30 days
615
61% of all-time downloads
ByronLeeee/EmbeddingGemma-300M-LawVault
EmbeddingGemma-300M-LawVault is a sentence similarity model from ByronLeeee. Use it when you need a score for how close two texts are. It is set up for sentence-transformers. The card lists the license as apache-2.0.
EmbeddingGemma-300M-LawVault is a high-performance embedding model fine-tuned specifically for Chinese Legal RAG (Retrieval-Augmented Generation) scenarios.
Downloads · 30 days
615
61% of all-time downloads
All-time downloads
1K
Public
Parameters
303M
1.3 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors1.2 GB · 97%
From the Hugging Face model README
EmbeddingGemma-300M-LawVault is a high-performance embedding model fine-tuned specifically for Chinese Legal RAG (Retrieval-Augmented Generation) scenarios.
Fine-tuned on Google's embeddinggemma-300m, this model employs a rigorous contrastive learning approach using MultipleNegativesRankingLoss and MatryoshkaLoss. It was trained on a high-quality dataset of over 60,000 (Query, Positive, Hard Negative) triplets to significantly improve retrieval accuracy for legal statutes, colloquial legal inquiries, and noise resistance compared to the base model.
Note: This model is fine-tuned exclusively on Chinese laws and regulations. Its performance on other languages or non-legal domains has not been evaluated and is not guaranteed.
The model was evaluated on a held-out test set constructed from real legal scenarios (containing 120 unseen colloquial legal queries generated by Deepseek V3.2). The End-to-End RAG retrieval results are as follows:
| Metric | Base Model | Finetuned Model (Ours) | Improvement |
|---|---|---|---|
| Hit Rate @ 10 | 85.0% | 98.0% | Significant reduction in "answer not found" cases |
| Top-1 Accuracy | 58.0% | 92.0% | Huge Leap (+34%), the vast majority of correct answers are ranked 1st |
| MRR @ 10 | 0.78 | 0.96 | Extremely high ranking quality |
Note: The test environment used a LanceDB vector database covering a full slice of the Chinese laws and regulations database.
| User Query | Base Model Rank | Finetuned Rank |
|---|---|---|
| "Can the provincial cultural relics bureau directly transfer artifacts unearthed in our area?" | ❌ Not Retrieved (10+) | ✅ 1st |
| "What are the legal requirements for merchants when setting product prices?" | ❌ Not Retrieved (10+) | ✅ 1st |
| "If land is requisitioned for a large hydropower station, how is compensation calculated?" | 2nd | ✅ 1st |
| "How does the government financially support rural revitalization?" | 6th | ✅ 1st |
pip install -U sentence-transformers
from sentence_transformers import SentenceTransformer
# Load model
model_path = "ByronLeeee/EmbeddingGemma-300M-LawVault"
model = SentenceTransformer(model_path, trust_remote_code=True)
# 1. Define Query
query = "What is the penalty for robbery?" # (In Chinese: 抢劫罪一般判几年?)
# 2. Define Documents - Recommended Format: title: {Law Name} | text: {Content}
documents = [
"title: 中华人民共和国刑法 第二百六十三条 | text: 以暴力、胁迫或者其他方法抢劫公私财物的,处三年以上十年以下有期徒刑,并处罚金...",
"title: 中华人民共和国刑法 第二百六十七条 | text: 抢夺公私财物,数额较大的,或者多次抢夺的,处三年以下有期徒刑、拘役或者管制...",
"title: 陕西省专利条例 第二十四条 | text: 负责专利执法的部门...可以查封或者扣押。"
]
# 3. Encode
query_vec = model.encode(query)
doc_vecs = model.encode(documents)
# 4. Compute Similarity
similarities = model.similarity(query_vec, doc_vecs)
print(similarities)
MatryoshkaLoss wrapping MultipleNegativesRankingLoss:
{
"matryoshka_dims": [768, 512, 256, 128],
"matryoshka_weights": [1, 1, 1, 1]
}
| Epoch | Step | Training Loss |
|---|---|---|
| 0.0022 | 1 | 3.5148 |
| ... | ... | ... |
| 1.0 | 457 | 0.2123 |
| 2.0 | 914 | 0.0749 |
| 3.0 | 1371 | 0.0369 |
If you use this model, please cite the following:
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}