Downloads · 30 days
919
0% of all-time downloads
truro7/vn-law-embedding
vn-law-embedding is a sentence similarity model from truro7. 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.
VN Law Embedding is a Vietnamese text embedding model designed for Retrieval-Augmented Generation (RAG), specifically to retrieve precise legal documents in response to legal questions.
Downloads · 30 days
919
0% of all-time downloads
All-time downloads
188K
Public
Parameters
278M
1.1 GB on disk
Likes
6
Public
Click a slice to open those files.
.safetensors1.1 GB · 98%
From the Hugging Face model README
VN Law Embedding is a Vietnamese text embedding model designed for Retrieval-Augmented Generation (RAG), specifically to retrieve precise legal documents in response to legal questions.
The model is trained on a dataset of Vietnamese legal questions and corresponding legal documents and evaluated using an Information Retrieval Evaluator.
It uses Matryoshka loss during training and can be truncated to smaller dimensions, allowing for faster comparisons between queries and documents without sacrificing performance.
from sentence_transformers import SentenceTransformer
import torch
import torch.nn.functional as F
model = SentenceTransformer("truro7/vn-law-embedding", truncate_dim = 128)
query = "Trộm cắp sẽ bị xử lý như thế nào?"
corpus = """
[100_2015_QH13]
LUẬT HÌNH SỰ
Điều 173. Tội trộm cắp tài sản
Khoản 1:
1. Người nào trộm cắp tài sản của người khác trị giá từ 2.000.000 đồng đến dưới 50.000.000 đồng hoặc dưới 2.000.000 đồng nhưng thuộc một trong các trường hợp sau đây, thì bị phạt cải tạo không giam giữ đến 03 năm hoặc phạt tù từ 06 tháng đến 03 năm:
a) Đã bị xử phạt vi phạm hành chính về hành vi chiếm đoạt tài sản mà còn vi phạm;
b) Đã bị kết án về tội này hoặc về một trong các tội quy định tại các điều 168, 169, 170, 171, 172, 174, 175 và 290 của Bộ luật này, chưa được xóa án tích mà còn vi phạm;
c) Gây ảnh hưởng xấu đến an ninh, trật tự, an toàn xã hội;
d) Tài sản là phương tiện kiếm sống chính của người bị hại và gia đình họ; tài sản là kỷ vật, di vật, đồ thờ cúng có giá trị đặc biệt về mặt tinh thần đối với người bị hại.
"""
embedding = torch.tensor([model.encode(query)])
corpus_embeddings = torch.tensor([model.encode(corpus)])
cosine_similarities = F.cosine_similarity(embedding, corpus_embeddings)
print(cosine_similarities.item()) #0.81
from sentence_transformers import SentenceTransformer
import torch
import torch.nn.functional as F
model = SentenceTransformer("truro7/vn-law-embedding", truncate_dim = 128)
all_docs = read_all_docs() # Read all legal documents -> list of document contents
top_k = 3
embedding_docs = torch.load(vectordb_path, weights_only=False).to(self.device) # Vector database
query = "Trộm cắp sẽ bị xử lý như thế nào?"
embedding = torch.tensor(model.encode(query))
cosine_similarities = F.cosine_similarity(embedding.unsqueeze(0).expand(self.embedding_docs.shape[0], 1, 128), self.embedding_docs, dim = -1).view(-1)
top_k = cosine_similarities.topk(k)
top_k_indices = top_k.indices
top_k_values = top_k.values
print(top_k_values) #Similarity scores
for i in top_k_indices: #Show top k relevant documents
print(all_docs[i])
print("___________________________________________")