Huy Dang
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -425,19 +425,23 @@ model-index:
|
|
425 |
|
426 |
# bkai-fine-tuned-legal
|
427 |
|
428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
|
430 |
## Model Details
|
431 |
|
432 |
### Model Description
|
433 |
- **Model Type:** Sentence Transformer
|
434 |
- **Base model:** [bkai-foundation-models/vietnamese-bi-encoder](https://huggingface.co/bkai-foundation-models/vietnamese-bi-encoder) <!-- at revision 84f9d9ada0d1a3c37557398b9ae9fcedcdf40be0 -->
|
435 |
-
- **Maximum Sequence Length:**
|
436 |
- **Output Dimensionality:** 768 dimensions
|
437 |
- **Similarity Function:** Cosine Similarity
|
438 |
-
- **
|
439 |
-
- json
|
440 |
-
- **Language:** vi
|
441 |
- **License:** apache-2.0
|
442 |
|
443 |
### Model Sources
|
@@ -468,48 +472,37 @@ pip install -U sentence-transformers
|
|
468 |
Then you can load this model and run inference.
|
469 |
```python
|
470 |
from sentence_transformers import SentenceTransformer
|
|
|
471 |
|
472 |
# Download from the 🤗 Hub
|
473 |
-
model = SentenceTransformer("
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
|
|
|
|
|
|
|
|
479 |
]
|
480 |
-
embeddings = model.encode(sentences)
|
481 |
-
print(embeddings.shape)
|
482 |
-
# [3, 768]
|
483 |
-
|
484 |
-
# Get the similarity scores for the embeddings
|
485 |
-
similarities = model.similarity(embeddings, embeddings)
|
486 |
-
print(similarities.shape)
|
487 |
-
# [3, 3]
|
488 |
-
```
|
489 |
-
|
490 |
-
<!--
|
491 |
-
### Direct Usage (Transformers)
|
492 |
-
|
493 |
-
<details><summary>Click to see the direct usage in Transformers</summary>
|
494 |
-
|
495 |
-
</details>
|
496 |
-
-->
|
497 |
-
|
498 |
-
<!--
|
499 |
-
### Downstream Usage (Sentence Transformers)
|
500 |
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
|
|
|
|
|
|
|
|
513 |
|
514 |
## Evaluation
|
515 |
|
|
|
425 |
|
426 |
# bkai-fine-tuned-legal
|
427 |
|
428 |
+
LEGAL-EMBEDDING is a Vietnamese text embedding focused on RAG and production efficiency:
|
429 |
+
|
430 |
+
📚 **Trained Dataset**:
|
431 |
+
The model was trained on an in-house dataset consisting of approximately **50,000 examples** of legal questions and their related contexts.
|
432 |
+
|
433 |
+
🪆 **Efficiency**:
|
434 |
+
Trained with a **Matryoshka loss**, allowing embeddings to be truncated with minimal performance loss. This ensures that smaller embeddings are faster to compare, making the model efficient for real-world production use.
|
435 |
|
436 |
## Model Details
|
437 |
|
438 |
### Model Description
|
439 |
- **Model Type:** Sentence Transformer
|
440 |
- **Base model:** [bkai-foundation-models/vietnamese-bi-encoder](https://huggingface.co/bkai-foundation-models/vietnamese-bi-encoder) <!-- at revision 84f9d9ada0d1a3c37557398b9ae9fcedcdf40be0 -->
|
441 |
+
- **Maximum Sequence Length:** 512 tokens
|
442 |
- **Output Dimensionality:** 768 dimensions
|
443 |
- **Similarity Function:** Cosine Similarity
|
444 |
+
- **Language:** vietnamese
|
|
|
|
|
445 |
- **License:** apache-2.0
|
446 |
|
447 |
### Model Sources
|
|
|
472 |
Then you can load this model and run inference.
|
473 |
```python
|
474 |
from sentence_transformers import SentenceTransformer
|
475 |
+
import torch
|
476 |
|
477 |
# Download from the 🤗 Hub
|
478 |
+
model = SentenceTransformer("quanghuy123/LEGAL_EMBEDDING")
|
479 |
+
|
480 |
+
# Define query (câu hỏi pháp luật) và docs (điều luật)
|
481 |
+
query = "Điều kiện để kết hôn hợp pháp là gì?"
|
482 |
+
docs = [
|
483 |
+
"Điều 8 Bộ luật Dân sự 2015 quy định về quyền và nghĩa vụ của công dân trong quan hệ gia đình.",
|
484 |
+
"Điều 18 Luật Hôn nhân và gia đình 2014 quy định về độ tuổi kết hôn của nam và nữ.",
|
485 |
+
"Điều 14 Bộ luật Dân sự 2015 quy định về quyền và nghĩa vụ của cá nhân khi tham gia hợp đồng.",
|
486 |
+
"Điều 27 Luật Hôn nhân và gia đình 2014 quy định về các trường hợp không được kết hôn.",
|
487 |
+
"Điều 51 Luật Hôn nhân và gia đình 2014 quy định về việc kết hôn giữa công dân Việt Nam và người nước ngoài."
|
488 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
|
490 |
+
# Encode query and documents
|
491 |
+
query_embedding = model.encode([query])
|
492 |
+
doc_embeddings = model.encode(docs)
|
493 |
+
similarities = torch.nn.functional.cosine_similarity(
|
494 |
+
torch.tensor(query_embedding), torch.tensor(doc_embeddings)
|
495 |
+
).flatten()
|
496 |
+
|
497 |
+
# Sort documents by cosine similarity
|
498 |
+
sorted_indices = torch.argsort(similarities, descending=True)
|
499 |
+
sorted_docs = [docs[idx] for idx in sorted_indices]
|
500 |
+
sorted_scores = [similarities[idx].item() for idx in sorted_indices]
|
501 |
+
|
502 |
+
# Print sorted documents with their cosine scores
|
503 |
+
for doc, score in zip(sorted_docs, sorted_scores):
|
504 |
+
print(f"Document: {doc} - Cosine Similarity: {score:.4f}")
|
505 |
+
```
|
506 |
|
507 |
## Evaluation
|
508 |
|