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.
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:
1from sentence_transformers import SentenceTransformer
2
3# Load model
4model_path = "ByronLeeee/EmbeddingGemma-300M-LawVault"
5model = SentenceTransformer(model_path, trust_remote_code=True)
6
7# 1. Define Query
8query = "What is the penalty for robbery?" # (In Chinese: 抢劫罪一般判几年?)
9
10# 2. Define Documents - Recommended Format: title: {Law Name} | text: {Content}
11documents = [
12 "title: 中华人民共和国刑法 第二百六十三条 | text: 以暴力、胁迫或者其他方法抢劫公私财物的,处三年以上十年以下有期徒刑,并处罚金...",
13 "title: 中华人民共和国刑法 第二百六十七条 | text: 抢夺公私财物,数额较大的,或者多次抢夺的,处三年以下有期徒刑、拘役或者管制...",
14 "title: 陕西省专利条例 第二十四条 | text: 负责专利执法的部门...可以查封或者扣押。"
15]
16
17# 3. Encode
18query_vec = model.encode(query)
19doc_vecs = model.encode(documents)
20
21# 4. Compute Similarity
22similarities = model.similarity(query_vec, doc_vecs)
23print(similarities)
1{
2 "matryoshka_dims": [768, 512, 256, 128],
3 "matryoshka_weights": [1, 1, 1, 1]
4}
1@inproceedings{reimers-2019-sentence-bert,
2 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
3 author = "Reimers, Nils and Gurevych, Iryna",
4 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
5 month = "11",
6 year = "2019",
7 publisher = "Association for Computational Linguistics",
8 url = "https://arxiv.org/abs/1908.10084",
9}