Huy Dang commited on
Commit
05b6f1a
·
verified ·
1 Parent(s): 42c44fb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -43
README.md CHANGED
@@ -425,19 +425,23 @@ model-index:
425
 
426
  # bkai-fine-tuned-legal
427
 
428
- This is a [sentence-transformers](https://www.SBERT.net) model finetuned from [bkai-foundation-models/vietnamese-bi-encoder](https://huggingface.co/bkai-foundation-models/vietnamese-bi-encoder) on the json dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
 
 
 
 
 
 
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:** 256 tokens
436
  - **Output Dimensionality:** 768 dimensions
437
  - **Similarity Function:** Cosine Similarity
438
- - **Training Dataset:**
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("sentence_transformers_model_id")
474
- # Run inference
475
- sentences = [
476
- 'Điều 29 Nghị định 46/2015 NĐ-CP quy định về thí nghiệm đối chứng, kiểm định chất lượng, thí nghiệm khả năng chịu lực của kết cấu công trình trong quá trình thi công xây dựng. Tôi xin hỏi, trong dự toán công trình giao thông có chi phí kiểm định tạm tính, chủ đầu tư có quyền lập đề cương, dự toán rồi giao cho phòng thẩm định kết quả có giá trị, sau đó thực hiện thuê đơn vị tư vấn có chức năng thực hiện công tác kiểm định được không?Bộ Xây dựng trả lời vấn đề này như sau:Trường hợp kiểm định theo quy định tại Điểm a, Điểm b, Điểm c, Khoản 2, Điều 29 (thí nghiệm đối chứng, kiểm định chất lượng, thí nghiệm khả năng chịu lực của kết cấu công trình trong quá trình thi công xây dựng) Nghị định46/2015/NĐ-CPngày 12/5/2015 của Chính phủ về quản lý chất lượng và bảo trì công trình xây dựng thì việc lập đề cương, dự toán kiểm định do tổ chức đáp ứng điều kiện năng lực theo quy định của pháp luật thực hiện.Đối với trường hợp kiểm định theo quy định tại Điểm đ, Khoản 2, Điều 29 Nghị định46/2015/NĐ-CPthì thực hiện theo quy định tại Điều 18 Thông tư26/2016/TT-BXDngày 26/10/2016 của Bộ Xây dựng quy định chi tiết một số nội dung về quản lý chất lượng và bảo trì công trình xây dựng.',
477
- 'Có thể thuê kiểm định chất lượng công trình?',
478
- 'Quy định về trợ cấp với cán bộ già yếu nghỉ việc',
 
 
 
 
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
- You can finetune this model on your own dataset.
502
-
503
- <details><summary>Click to expand</summary>
504
-
505
- </details>
506
- -->
507
-
508
- <!--
509
- ### Out-of-Scope Use
510
-
511
- *List how the model may foreseeably be misused and address what users ought not to do with the model.*
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 gì?"
482
+ docs = [
483
+ "Điều 8 Bộ luật Dân sự 2015 quy định về quyền 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